Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to view colum as row from 1 table?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2010-02-11 : 09:52:05
Hi

I am using SQl 2005 standard and the table (tblA) as below.

ORDUNIQ -----OPTFIELD-------VALUE
111 ------ COMM -------Null
111 ------DESP ------- 20091221
111 ------MANI ------- 1
354 ------ COMM -------
354 ------DESP ------- 20090614
354 ------MANI ------- 4

Expected Result is

ORDUNIQ ----Comm ------Desp--------MANI
111-------- Null ----20091221------ 1
354------- ----20090614------ 4

Plesae help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 09:56:44
[code]SELECT ORDUNIQ,
MAX(CASE WHEN OPTFIELD='COMM' THEN VALUE ELSE NULL END) AS COMM,
MAX(CASE WHEN OPTFIELD='DESP' THEN VALUE ELSE NULL END) AS DESP,
MAX(CASE WHEN OPTFIELD='MANI' THEN VALUE ELSE NULL END) AS MANI
FROM tblA
GROUP BY ORDUNIQ
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2010-02-11 : 10:10:32
Hi

Its perfect . THANKS a LOT

quote:
Originally posted by visakh16

SELECT ORDUNIQ,
MAX(CASE WHEN OPTFIELD='COMM' THEN VALUE ELSE NULL END) AS COMM,
MAX(CASE WHEN OPTFIELD='DESP' THEN VALUE ELSE NULL END) AS DESP,
MAX(CASE WHEN OPTFIELD='MANI' THEN VALUE ELSE NULL END) AS MANI
FROM tblA
GROUP BY ORDUNIQ


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 10:13:17
Welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -