In SQL Server I have dynamic sql query, but the size of the query is higher than 4000 chars. Like in this post SQL Server 2012: dynamic SQL limitation ( > 4000 chars) (split) there is no problem to manage with this issue. But the problem is when I want to join string with variable. For example, this works ok:
DECLARE @sqlQuery NVARCHAR(MAX);
DECLARE @sqlQueryWhere NVARCHAR(MAX);
SET @sqlQuery =
CONVERT(nvarchar(max),'SELECT
.... '
EXECUTE sp_executesql @sqlQuery
But this sample doesn't work:
DECLARE @sqlQuery NVARCHAR(MAX);
DECLARE @sqlQueryWhere NVARCHAR(MAX);
SET @sqlQueryWhere = CONVERT(nvarchar(max),' 1 = 1 ' )
SET @sqlQuery =
CONVERT(nvarchar(max),'SELECT
.... ' + @sqlQueryWhere + ' group by ... '
EXECUTE sp_executesql @sqlQuery