SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Return multiple rows data in a single line
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

swapna.anu
Starting Member

3 Posts

Posted - 04/04/2012 :  05:39:29  Show Profile  Reply with Quote
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


Edited by - swapna.anu on 04/04/2012 05:42:03

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/04/2012 :  20:30:06  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000