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:34:58
|
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 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-11-14 : 13:10:30
|
You can make a slight tweak then you don't need to remove a comma: SELECT @List = (@List + CASE WHEN @List <> '' THEN ', ' ELSE '' END + HIXID) FROM @TempGroup PRINT @List |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|