Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 merge record
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Joetaniarto00
Starting Member

Indonesia
12 Posts

Posted - 03/03/2015 :  22:52:35  Show Profile  Reply with Quote
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

Indonesia
12 Posts

Posted - 03/04/2015 :  21:03:41  Show Profile  Reply with Quote
and also if there were null value, it shows an error...

thx
Go to Top of Page

gbritton
Flowing Fount of Yak Knowledge

2780 Posts

Posted - 03/05/2015 :  04:20:21  Show Profile  Reply with Quote
Select @var = @var + ...

Is not supported and can give wrong results. Use for XML path('') instead
Go to Top of Page

Joetaniarto00
Starting Member

Indonesia
12 Posts

Posted - 03/05/2015 :  04:44:17  Show Profile  Reply with Quote
so have you any solution of the problems?

thanks
Go to Top of Page

gbritton
Flowing Fount of Yak Knowledge

2780 Posts

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

Joetaniarto00
Starting Member

Indonesia
12 Posts

Posted - 03/05/2015 :  23:26:49  Show Profile  Reply with Quote
could you give me the example?

thx
Go to Top of Page

huangchen
Starting Member

USA
37 Posts

Posted - 04/02/2015 :  05:57:36  Show Profile  Reply with Quote
unspammed
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000