using a local variable to build an sql-statement beyond datatype nvarchar(4000) and execute with sp_executesql

25 pts.
Tags:
SQL
SQL Server
I build a sql-statement and put it in a local variable so i can execute it using sp_executesql, but a local variable cannot be a text or ntext data type, and a varchar data type cannot be used by sp_executesql. So the maximum lenght of the statement cannot be more than nvarchar(4000)... is there any work around?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Pretty much no. I ran into this same problem with some dynamic SQL that we had, and I had to remove some of the code from the dynamic SQL and pass it’s results into the sp_executesql via the parameter.

Do as much of the logic as you can outside of the dynamic SQL so that only the final select statement is dynamic.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following