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 2000 Forums
 Transact-SQL (2000)
 Query for Convert Variable No of Rows into columns

Author  Topic 

muralidaran_r
Starting Member

13 Posts

Posted - 2008-07-16 : 02:32:07
I am having data in a table like this:

ID Name Value Posn
HOXE EMAIL g.mang@tjh.com 30
HOXE EMAIL g1.mang1@tjh.com 31
HOXE FAX 91-821-2660585 20
HOXE PHONE 91-821-2660420 10

KTSA EMAIL ga.jais@tjh.com 30
KTSA FAX 91-2990-150444 20
KTSA PHONE 91-2990-151874 10
KTSA PHONE 91-2990-152638 11


LTSA EMAIL la.lais@tjh.com 30
LTSA FAX 91-2997-550444 20
LTSA FAX 91-2997-550444 21
LTSA PHONE 91-2997-551874 10



I want output with 4 columns like this:
ID Phone Fax Email
HOXE 91-821-2660420 91-821-2660585 g.mang@tjh.com, g1.mang1@tjh.com
KTSA 91-2990-151874, 91-2990-152638 91-2990-150444 ga.jais@tjh.com
LTSA 91-2997-551874 91-2997-550444, 91-2997-550444 la.lais@tjh.com

If more than 1 phone or email or fax is available then it should be concated with comma seperation.

Can you Please Help?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-16 : 04:08:09
What you need is PIVOT or a CROSSTAB query.
There are lot of examples of this. Please make use of the SEARCH utility.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-16 : 10:01:32
refer this too:-
http://www.projectdmx.com/tsql/rowconcatenate.aspx

Go to Top of Page
   

- Advertisement -