• subscribe
October 23, 2002 12:00 AM

Character Limitation in sp_executesql

SQL Server Pro
InstantDoc ID #26614

I notice that when I use the sp_executesql system stored procedure in a script, my script can't exceed 4000 characters. What's the reason for this character limitation?

The sp_executesql statement's @stmt parameter is a Unicode string. Therefore, given that the maximum string length in SQL Server 2000 is 8000 bytes (without using an ntext data type) and that each character in Unicode is 2 bytes, 4000 characters is the maximum that sp_executesql can accept.



ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    May 19, 2005

    But given that the OP is wanting to use sp_executesql does your answer which uses exec() do the same thing..?

  • Anonymous User
    7 years ago
    Feb 18, 2005

    Try this
    declare @Sql_1 nvarchar(4000)
    declare @Sql_2 nvarchar(4000)
    :
    :
    :
    declare @Sql_n nvarchar(4000)

    ...build you statements split over the @Sql_n vars

    exec(@Sql_1 + @Sql_2 + ....+ @Sql_n)


    Good Luck

  • Anonymous User
    7 years ago
    Feb 03, 2005

    Yes, well then lets see the code, otherwise you not helping enybody but your own ego...

  • Anonymous User
    8 years ago
    Nov 24, 2004

    This isn't true. A developer and I have put together multiple 8000 varchar values and executed them with sp_executesql

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...