August 17, 2007 at 7:28 am
Hi ,
I need to transpose the column name to row( without using any function) ,can anybody help me to sort out this problem ?
Example :
select sum(ParAmt )ParAmt ,
sum(DenomQty )DenomQty ,
sum(convert(float,CInsNbr))CInsNbr,
sum(convert(float,HNbr))HNbr
from CHold
output :
ParAmt DenomQty CInsNbr HNbr
92376.9341 121.0 131852658.0 2281.0
But i like to display the output as
ParAmt 92376.9341
DenomQty 121.0
CInsNbr 131852658.0
HNbr 2281.0
( Note : I dont want to use any system or predefined functions.
I need a pure sql code to complete this issue )
Regards
Karthik
karthik
August 17, 2007 at 8:01 am
SELECT
CASE N.Number
WHEN 1 THEN 'ParAmt'
WHEN 2 THEN 'DenomQty'
WHEN 3 THEN 'CInsNbr'
WHEN 4 THEN 'HNbr'
END AS Col
,CASE N.Number
WHEN 1 THEN ParAmt -- cast to float if not already float
WHEN 2 THEN DenomQty -- cast to float if not already float
WHEN 3 THEN CInsNbr
WHEN 4 THEN HNbr
END AS Value
FROM (
SELECT SUM(ParAmt ) AS ParAmt
,SUM(DenomQty ) AS DenomQty
,SUM(CAST(CInsNbr AS float)) AS CInsNbr
,SUM(CAST(HNbr AS float)) AS HNbr
FROM CHold
) D
CROSS JOIN (
SELECT 1 UNION ALL
SELECT 2 UNION ALL
SELECT 3 UNION ALL
SELECT 4
) N (Number)
August 17, 2007 at 9:44 pm
>>I need a pure sql code to complete this issue
Why?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 20, 2007 at 3:18 am
Because , the same sql query will be execute from both the sybase and sqlserver2000 server. That's why i am asking pure sql code (without using any specific sqlserver related functions).
Regards
Karthik
karthik
August 20, 2007 at 4:05 am
Do you think this is vital information?
If so, you should have posted this in your original post.
N 56°04'39.16"
E 12°55'05.25"
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply