I have the following SQL Query. There is a lot more happening (basically a lot of conditional statements adding to the end of these variables) but I tried to simplify it just because I want to know if it is related to the order
DECLARE @sql NVARCHAR(MAX)
DECLARE @tempTableBuild NVARCHAR(MAX)
DECLARE @insertTempTableBuild NVARCHAR(MAX)
SET @sql = N'a very very long query...';
SET @tempTableBuild = N'DECLARE @results table
(
Index1 INT,
Index2 INT,
Index3 INT
)'
SET @insertTempTableBuild = N'INSERT INTO @results
(
Index1,
Index2,
Index3
)'
DECLARE @lastSQL NVARCHAR(MAX)
SET @lastSQL = @tempTableBuild
SET @lastSQL += @insertTempTableBuild
SET @lastSQL += @sql
Why is my @lastSQL variable getting chopped? Is it because they should be in a certain order? Or is it not related to the order at all?