Reputation: 7693
In my old Stored Proceder result returned in form of counts . it returned as below. Result is correct but now I want this row result in form of table. Please look into this and help me.
Result in form of Row:
SELECT 100 AS A ,200 AS B ,300 AS C
Required Result in form of column:
TextKey | TextValue
---------------------
A 100
B 200
C 300
Thanks in Advance.
Upvotes: 1
Views: 122
Reputation: 9724
Query: SQLFIDDLEExample
SELECT a.*
FROM (VALUES ('A', 100),
('B', 200),
('C', 300)) as a(TextKey, TextValue)
Result:
| TEXTKEY | TEXTVALUE |
-----------------------
| A | 100 |
| B | 200 |
| C | 300 |
Upvotes: 1
Reputation: 4604
select TextKey, TextValue
from (
SELECT 100 AS A ,200 AS B ,300 AS C
) t unpivot (TextValue for TextKey in ([A], [B], [C])) tp
Upvotes: 2
Reputation: 58431
Simplest would be to use a UNION ALL
SELECT 'A' AS TextKey, 100 AS TextValue UNION ALL
SELECT 'B', 200 UNION ALL
SELECT 'C', 300
Upvotes: 3