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
 General SQL Server Forums
 New to SQL Server Programming
 Query Help !!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kjs
Starting Member

3 Posts

Posted - 04/25/2013 :  10:47:38  Show Profile  Reply with Quote
Hi,

I have a requirement where i need to display the result set from row to column with space seperated values.

My query and result set :

select distinct filename from FileDetails where filetype='PST';

FileName
-----------------
09801001
09801002
09801003
09801004
09802001

Now, i need a query to write the result set in below format with space separated: The result set is dynamic and it changes depending upon the data.

09801001 09801002 09801003 09801004 09802001

Any help please !! Thanks in advance..

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/25/2013 :  11:03:06  Show Profile  Reply with Quote

SELECT STUFF((SELECT ' ' + FileName FROM Table FOR XML PATH('')),1,1,'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kjs
Starting Member

3 Posts

Posted - 04/25/2013 :  11:32:39  Show Profile  Reply with Quote
quote:
Originally posted by visakh16


SELECT STUFF((SELECT ' ' + FileName FROM Table FOR XML PATH('')),1,1,'')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Sorry I didnt get: what is XML PATH ??

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/25/2013 :  11:45:09  Show Profile  Reply with Quote
it creates a XML document from resultset. In this case its used to create a dummy xml document which will contain the delimited list

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

kjs
Starting Member

3 Posts

Posted - 04/25/2013 :  20:40:10  Show Profile  Reply with Quote
That was awesome!!! It worked as I needed it.. Thanks :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 04/26/2013 :  00:17:28  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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