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 2008 Forums
 Transact-SQL (2008)
 select @extra = @extra + fullname from customers

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2013-05-12 : 05:07:28
Hi all,

For some reason this is not working
select @extra = @extra + CAST(shipdate AS nvarchar(255)) + '<br>' from orders

when i just do this it returns a records set it returns 2 records

any idea what is wrong

thanks a lot

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-12 : 10:13:42
Seems fine to me, assuming you are declaring and initializing @extra:

declare @extra nvarchar(max);
set @extra = '';
select @extra = @extra + cast(shipdate as nvarchar(255)) + '<br>' from orders;
select @extra;
You can also try the following (which has the added benefit that it will let you order the dates if you need to so they appear in a predictable order in the final string
select 
CAST(
(select cast(shipdate as nvarchar(255)) + '<br>' from orders for xml path(''))
as xml).value('.','nvarchar(max)')
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2013-05-13 : 13:19:49
How many records are you expecting?

=================================================
There are two kinds of light -- the glow that illuminates, and the glare that obscures. -James Thurber
Go to Top of Page
   

- Advertisement -