Resolves an issue where SQL statements are truncated due to lengthy SQL string concatenation in stored procedures

Source: Internet
Author: User

Today, a wonderful problem is encountered: The SQL string stitching in the stored procedure is too long, beyond the length of the nvarchar (4000) that the paging stored procedure executes the SQL parameter.

No way, you can only modify your own stored procedures, because the paging stored procedure is not moving.

The first way to think of it is to extract the inner SELECT statement, execute it with exec (Strinnersql), put the query data into a temporary table, use temporary tables in @s to get the data, and end up in the Times.

Error reason: The temporary table generated by EXEC (Strinnersql) was not found when executing the @s statement

Good depressed ah, how can this, clearly in a stored procedure execution, how temporary table can not get it??????????

It's going to be a long day.

Helpless, only the exec (strinnersql) execution of the SQL extracted, executed in code, let him produce a temporary table, and then in the stored procedure call

Surprised, incredibly successful.!!!!!!!!

God, can you tell me why?????????????????????????????

The first method why not, the second method is OK

Which big God is passing, must tell me to ask what!!!!!!!!!!!!!!

Resolves an issue where SQL statements are truncated due to lengthy SQL string concatenation in stored procedures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.