Dynamic SQL character length exceeding 8000

Source: Internet
Author: User

With a dynamic SQL character length of more than 8000, I remember using sp_executesql in SQL SERVER 2008 to break this limitation.

Normally with dynamic SQL, EXEC () may be used, but there is a limit of 8000 string lengths. Since SQL SERVER 2005, it has been mentioned in INSIDE Server 2005 T-SQL programming that using sp_executesql () and nvarchar (MAX) can exceed the 8,000-character limit. Because sp_executesql () must use Nvarchar,nchar,ntext as a parameter, the maximum character limit for sp_executesql () is 4000.

Let's look at a nvarchar (4000) Example:

How to break this limit, let's look Again (set the SQL character variable type to nvarchar (MAX)):

As you can see, a dynamic SQL with a SQL character length of 9999 was successfully executed.

See an example of more than 100000 SQL characters:

String length is huge, I can only save the results to the RPT file, unfortunately, my machine (2.5 memory + 32-bit WIN2003) still can not display, must be insufficient resources

Dynamic SQL character length exceeding 8000

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.