• Fortunately the 4000 character limit is an expression limitation, not a limitation of the number of characters in the string.

    I have not done this personally but you might be able to break your expression down into parts and set a variable to each section. For example Var1, Var2, Var3, SQLVar. Then

    Var1 = SELECT........

    Var2 = FROM.....

    Var3 = WHERE....

    SQLVar = Var1 + Var2 + Var3

    If that doesn't work the other way is to pull the query as suggested above from SQL built as a stored procedure, or from a column in a table that stores the entire query, and then set your variable value to the string returned.