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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 showing column as rows....

Author  Topic 

mrsaif
Starting Member

43 Posts

Posted - 2008-04-26 : 04:25:54
i have 2 columns like
Col1====col2
username=======saif====mr@hotmai.com
email=======saif@hotmail.com
name======saifullah
I want to get these records from sql like
username email name
saif saif@hotmail.com saifullah
________________________________-
how can I achive this

Muhammad Saifullah

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-26 : 04:47:07
SELECT IDColumn,
MAX(CASE WHEN Col1='username' THEN Col2 END) AS usename,
MAX(CASE WHEN Col1='email' THEN Col2 END) AS email,
MAX(CASE WHEN Col1='name' THEN Col2 END) AS name

FROM YourTable
GROUP BY IDColumn
Go to Top of Page

mrsaif
Starting Member

43 Posts

Posted - 2008-04-26 : 05:04:11
in this case only one record is select...What if i have multipule records for username email and name??????

Muhammad Saifullah
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-26 : 05:16:55
Nope. You will get one record for each id in your table. Post you table structure and some sample data if you want the complete solution.
Go to Top of Page
   

- Advertisement -