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
 SQL Server Development (2000)
 Return multiple rows data in a single line

Author  Topic 

swapna.anu
Starting Member

3 Posts

Posted - 2012-04-04 : 05:39:29
Hi All,

I am trying to write a sql query using sql server 2000. My query and the result set looks like below

select h.UPRN, h.address1 as fulladdress, h.jobid, h.engineername, l.make as boilermake, l.model as boilermodel,
l.locationcode, l.apptype, h.tightness, h.emergency as emergencycontrols, l.serialno, l.cp12labwarn
from tblcp12_lines l join tblcp12_headers h on h.jobid = l.jobid
where h.jobid = '700936' and isnull(CP12Status,'') <> 'Removed' and isnull(CP12Details,'') <> 'NO GAS FOUND IN PROPERTY.'

UPRN fulladdress jobid EngineerName Boilermake BoilerModel locationcode apptype tightness emergencycontrols serialno cp12labwarn
6224156 52, Ridgeview Close 700936 Jonathan Afshin NEW WORLD UNK KITCHEN COOKER Pass Yes UNKNOWN NULL
6224156 52, Ridgeview Close 700936 Jonathan Afshin POTTERTON PROFILE 50E COMPARTMENT BOILER Pass Yes UNKNOWN No
6224156 52, Ridgeview Close 700936 Jonathan Afshin UNKNOWN UNK FRONT ROOM GAS FIRE Pass Yes UNKNOWN No
6224156 52, Ridgeview Close 700936 Jonathan Afshin CARBON MONOXIDE DETETOR FIREANGEL BEDROOM Carbon Monoxide dete Pass Yes UNKNOWN NULL
6224156 52, Ridgeview Close 700936 Jonathan Afshin UNKNOWN UNK HALL Smoke detector Pass Yes UNKNOWN NULL

I want to change it to return in a single row which should have all the details similar to the line in apptype as Boilder and along with that i need to get other appliance types like below

6224156 , 52,Ridgeview Close, 700936, Jonathan Afshin, Potterton, Profile 50E, Compartment, Boiler, Cooker, Gas Fire, Carbon Monoxide dete, Pass , Yes, No (This is cp12labwarn which should be No if any one of the rows contains No otherwise Null)

Please do let me know if you need more details to get this results.

I am using SQL Server 2000.

Thanks in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-04 : 20:30:06
you need to use a UDF for that

http://geekswithblogs.net/mnf/archive/2007/10/02/t-sql-user-defined-function-to-concatenate-column-to-csv-string.aspx

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

Go to Top of Page
   

- Advertisement -