Stored Procedure varchar (8000) limitation.

SELECT @qry = CAST(@qry1 AS VARCHAR(MAX)) + CAST(@qry2 AS VARCHAR(MAX))

– ————————————————————–

– You would expect the length of @qry to be 10,000 at this point

– But that is not true. The length will be 8000.

– ————————————————————–

SELECT

LEN(@qry) AS sqlLength,

LEN(@qry1) AS sql1Length ,

LEN(@qry2) AS sql2Length

/*

sqlLength            sql1Length  sql2Length

——————– ———– ———–

10000                5000        5000

*/

 For SQL Server 2005 or higher

Leave a Reply