Hello,
I remember back in the day I would make a whole wack of nvarchar(4000)
vars, check the length of them as they grew, switch them out as they filled up and then concatenate the whole mess together for the exec call. I was wondering if there was an easier way of doing it.
Thanks!
Edit:
Code Sample, shows me screwing up the case statement
DECLARE @sql NVARCHAR(MAX)
SELECT @sql = CAST(N'SELECT ' AS NVARCHAR(MAX))
DECLARE @Index INT
SELECT @Index = 0
WHILE (@Index < 1000)
BEGIN
SELECT @sql = CAST(@sql AS NVARCHAR(MAX)) + CAST(N' ' AS NVARCHAR(MAX)) + CAST( CASE @Index WHEN 1 THEN N' ' END AS NVARCHAR(MAX))
SELECT @Index = @Index + 1
END
SELECT @sql = CAST(@sql AS NVARCHAR(MAX)) + CAST(1 AS NVARCHAR(MAX))
SELECT LEN(@sql)
EXECUTE sp_executesql @sql