April 21, 2008 at 3:35 am
@sql starts off as null, and you keep appending to it - which will always give null. You need to set @sql...
DECLARE @Count int
DECLARE @sql NVARCHAR(2000)
SET @sql = '' -- You need this
SET @Count = 1
WHILE @Count < 20
BEGIN
SET @sql = @sql + ' Test ' + CAST(@Count AS NVARCHAR)
SET @Count = @Count + 1
END
SELECT @sql
Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
April 21, 2008 at 3:44 am
Great. That works. Thanks for the help!
April 21, 2008 at 4:07 am
Or you can modify your code little.
Hi All,
Any ideas why this always returns NULL? Help would be greatly appreciated!
DECLARE @Count int
DECLARE @sql NVARCHAR(2000)
SET @Count = 1
WHILE @Count < 20
BEGIN
SET @sql = isnull(@sql,'') + ' Test ' + CAST(@Count AS NVARCHAR)
SET @Count = @Count + 1
END
SELECT @sql
karthik
April 28, 2008 at 8:11 am
Or use SET CONCAT_NULL_YIELDS_NULL OFF in your SP...
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply