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 |
Joetaniarto00
Starting Member
12 Posts |
Posted - 2015-03-03 : 22:52:35
|
Hi,I have some data as below :ID remark14010061 3401005614010061 3401005714010061 3401006914010061 34010168I create syntax as :SELECT @combinedString = COALESCE(@combinedString + ', ', '') + remarkFROM view_bhp WHERE id='14010061' SELECT @combinedString as remarkso the result can be this :remark34010056, 34010057, 34010069, 34010168But the ID cannot displayed, please tell me where is my mistakes..thanks |
|
Joetaniarto00
Starting Member
12 Posts |
Posted - 2015-03-04 : 21:03:41
|
and also if there were null value, it shows an error...thx |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-03-05 : 04:20:21
|
Select @var = @var + ...Is not supported and can give wrong results. Use for XML path('') instead |
|
|
Joetaniarto00
Starting Member
12 Posts |
Posted - 2015-03-05 : 04:44:17
|
so have you any solution of the problems?thanks |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-03-05 : 08:16:27
|
Yes, use select...for xml path ('') |
|
|
Joetaniarto00
Starting Member
12 Posts |
Posted - 2015-03-05 : 23:26:49
|
could you give me the example? thx |
|
|
huangchen
Starting Member
37 Posts |
Posted - 2015-04-02 : 05:57:36
|
unspammed |
|
|
|
|
|