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.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 merge record

Author  Topic 

Joetaniarto00
Starting Member

12 Posts

Posted - 2015-03-03 : 22:52:35
Hi,

I have some data as below :
ID remark
14010061 34010056
14010061 34010057
14010061 34010069
14010061 34010168

I create syntax as :
SELECT @combinedString = COALESCE(@combinedString + ', ', '') + remark
FROM view_bhp
WHERE id='14010061'
SELECT @combinedString as remark

so the result can be this :
remark
34010056, 34010057, 34010069, 34010168

But 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
Go to Top of Page

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
Go to Top of Page

Joetaniarto00
Starting Member

12 Posts

Posted - 2015-03-05 : 04:44:17
so have you any solution of the problems?

thanks
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-03-05 : 08:16:27
Yes, use select...for xml path ('')
Go to Top of Page

Joetaniarto00
Starting Member

12 Posts

Posted - 2015-03-05 : 23:26:49
could you give me the example?

thx
Go to Top of Page

huangchen
Starting Member

37 Posts

Posted - 2015-04-02 : 05:57:36
unspammed
Go to Top of Page
   

- Advertisement -