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)
 How to change some columns into rows

Author  Topic 

sqlmind
Starting Member

1 Post

Posted - 2010-06-28 : 20:28:41
Hi,

I've a query in which i need to change some of the columns into rows.
Please see the example;

Existing query
--------------
[Emp_Name] [PHN] [MOB] [OTH]
[Steve] [223] [456] [895]
[John] [789] [789] [421]
[jack] [ ] [252] [252]


I need this query to be changed in a format like this..
[Emp_Name] [NMBR] [TYP]
[Steve] [223] [P]
[Steve] [456] [M]
[Steve] [895] [O]
[John] [789] [P+M]
[John] [421] [O]
[jack] [252] [M+O]



Please let me know that if anyone got logic..

Regards

Robz



sql-programmers
Posting Yak Master

190 Posts

Posted - 2010-06-30 : 05:49:21
Hi,

I have a blog article to maybe assist you with your question:

http://www.sql-programmers.com/Blog/tabid/153/EntryId/6/Using-PIVOT-and-UNPIVOT.aspx

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page
   

- Advertisement -