I want to convert rows 2 rows as 2 columns in sql 2000 without using pivot
I wa开发者_StackOverflow中文版nt to convert rows 2 rows as 2 columns in sql 2000 without using pivot
eg:
A B C
---- ---- -------
78 68 3
I want the output as
Projects Count
--------- -------
A 78
B 68
C 3
SELECT
pivot.field,
CASE pivot.field
WHEN 'A' THEN A
WHEN 'B' THEN B
WHEN 'C' THEN C
END as value
FROM
my_table
CROSS JOIN
(SELECT 'A' AS field UNION ALL SELECT 'B' UNION ALL SELECT 'C') AS pivot
If I understand you correctly, you indeed want a pivot query:
select 'A' as Projects, A as my_count from mytab
union all
select 'B' as Projects, B as my_count from mytab
union all
select 'C' as Projects, C as my_count from mytab
(I've replaced count with my_count, since COUNT is a reserved word in SQL).
精彩评论