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 |
NguyenL71
Posting Yak Master
228 Posts |
Posted - 2013-11-14 : 12:40:13
|
It looks simple but I try different way and can't get this to work, I have a list of id concat them and remove the last comma at theend. Please see the results desire below. Thank you so much. SQL 2012DECLARE @TempGroup TABLE ( CounterId INT IDENTITY(1,1) NOT NULL, HIXID VARCHAR(50) NULL);INSERT @TempGroupSELECT 220100000000002UNIONSELECT 220100000000003UNIONSELECT 120000000000001UNIONSELECT 150000000000007DECLARE @List VARCHAR(8000)SET @List = '' SELECT @List = (@List + HIXID + ', ') FROM @TempGroup PRINT @List--Result want:120000000000001, 150000000000007, 220100000000002, 220100000000003 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-14 : 13:22:58
|
[code]DECLARE @TempGroup TABLE (CounterId INT IDENTITY(1,1) NOT NULL,HIXID VARCHAR(50) NULL);INSERT @TempGroupSELECT 220100000000002UNIONSELECT 220100000000003UNIONSELECT 120000000000001UNIONSELECT 150000000000007SELECT STUFF((SELECT ',' + HIXID FROM @TempGroup ORDER BY CAST(HIXID AS bigint) FOR XML PATH('')),1,1,'')output--------------------------------120000000000001,150000000000007,220100000000002,220100000000003[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
NguyenL71
Posting Yak Master
228 Posts |
Posted - 2013-11-14 : 14:10:51
|
visakhm,Thank you so much. I try similar logic before on my end but it did not work but your work.Again, thank you.quote: Originally posted by visakh16
DECLARE @TempGroup TABLE (CounterId INT IDENTITY(1,1) NOT NULL,HIXID VARCHAR(50) NULL);INSERT @TempGroupSELECT 220100000000002UNIONSELECT 220100000000003UNIONSELECT 120000000000001UNIONSELECT 150000000000007SELECT STUFF((SELECT ',' + HIXID FROM @TempGroup ORDER BY CAST(HIXID AS bigint) FOR XML PATH('')),1,1,'')output--------------------------------120000000000001,150000000000007,220100000000002,220100000000003 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
Rajan Sahai
Starting Member
8 Posts |
Posted - 2013-11-23 : 01:59:37
|
unspammed |
|
|
|
|
|
|
|