Unix Technical Forum

Varchar Truncation

This is a discussion on Varchar Truncation within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I am attempting to write a stored procedure that builds and executes a dynamic SQL statement which can ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 01:09 PM
Chris Moore
 
Posts: n/a
Default Varchar Truncation

Hello,

I am attempting to write a stored procedure that builds and executes a
dynamic SQL statement which can be up to 8000 characters long.
Therefore, I have declared a variable of type varchar(8000) which,
according to the documentation, is the maximum acceptable length of
such a variable. Unfortunately, however, SQL Server seems allow
varchars to only be half this size: the resulting string keepings
getting truncated to 4000 characters as reported by the len function.

Is there setting somewhere that would fix this behavior or some
work-around that I can employ that would allow me to execute a dynamic
sql statement that is longer than 4000 characters?

(note: I am not using the sp_executesql proc as it maxes out at 4000; I
am simply calling EXEC which, according to the docs, should be fine)

Thank You.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 01:10 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Varchar Truncation

Chris Moore (CMoore@gmail.com) writes:
> I am attempting to write a stored procedure that builds and executes a
> dynamic SQL statement which can be up to 8000 characters long.
> Therefore, I have declared a variable of type varchar(8000) which,
> according to the documentation, is the maximum acceptable length of
> such a variable. Unfortunately, however, SQL Server seems allow
> varchars to only be half this size: the resulting string keepings
> getting truncated to 4000 characters as reported by the len function.


I don't want to belittle you, but it sounds like you are spelling
"varchar" with a leading "n".

Anyway, without seeing the code, I cannot say much more.

Except that it you are on SQL 2005, you should use varchar(MAX) instead.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com