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.
Author |
Topic |
kjs
Starting Member
3 Posts |
Posted - 2013-04-25 : 10:47:38
|
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-----------------0980100109801002098010030980100409802001Now, 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 09802001Any help please !! Thanks in advance.. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-25 : 11:03:06
|
[code]SELECT STUFF((SELECT ' ' + FileName FROM Table FOR XML PATH('')),1,1,'')[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
kjs
Starting Member
3 Posts |
Posted - 2013-04-25 : 11:32:39
|
quote: Originally posted by visakh16
SELECT STUFF((SELECT ' ' + FileName FROM Table FOR XML PATH('')),1,1,'') ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsSorry I didnt get: what is XML PATH ??
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-25 : 11:45:09
|
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
kjs
Starting Member
3 Posts |
Posted - 2013-04-25 : 20:40:10
|
That was awesome!!! It worked as I needed it.. Thanks :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-26 : 00:17:28
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|