Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,i want to display single column with multiple rows to a singl column..is there any way to acheive this using sql query..Select ID From TempID123456o/p should look like ID1 2 3 4 5 6Thanks in Advance..
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-11-17 : 02:06:50
[code]SELECT STUFF((SELECT ' ' + CAST(ID AS varchar(10)) FROM table ORDER BY ID FOR XML PATH('')),1,1,'')[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
raghav99k
Starting Member
32 Posts
Posted - 2011-11-17 : 02:13:16
Thanks Visakh..U r really awesome.
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2011-11-17 : 03:59:54
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
Sachin.Nand
2937 Posts
Posted - 2011-11-17 : 04:22:25
Hmm why do you need XML PATH for this ?
declare @t table(id int)insert @tselect 1 union allselect 2 union allselect 3 union allselect 4declare @id varchar(10)=''select @id=@id +',' + convert(varchar(10),ID) from @tselect stuff(@id, 1,1,'')