Groups | Blog | Home
all groups > sql server programming > september 2006 >

sql server programming : VARCHAR(8000) Does Not Work


hufaunder NO[at]SPAM yahoo.com
9/10/2006 9:19:44 PM
I have a table with a field of type varchar(8000). Unfortunately, I am
not able to store more then approx 3900 characters. This is the error I
get:

Disallowed implicit conversion from data type ntext to data type
varchar, table xxx column yyy Use the CONVERT function to run this
query.

I have a feeling it might have something to do with Unicode/Multibyte
characters. Nevertheless, when I look at the values in SQL Server
Enterprise Manager and also copy them to WinWord I do not see that it
uses 16-bits/char (maybe it automatically handles this for display
purposes). In any case, how can I store 8000 characters in the field?

I am using Visual Studio 2005, C# and SQL Server 2000.

Thanks
Steve Kass
9/11/2006 12:46:21 AM
Try

SELECT DATALENGTH(
N'the long Unicode string with 3900 characters that won't convert to
varchar'
)

and see if the result is over 8000.

Steve Kass
Drew University
http://www.stevekass.com

[quoted text, click to view]
John Bell
9/13/2006 1:09:02 AM
Hi

Out of interest what other columns are there in this table and how large are
they?
The Bytes per row is 8,060 for SQL 7/2000.

John

[quoted text, click to view]
hufaunder NO[at]SPAM yahoo.com
9/16/2006 12:24:22 AM
John,

In one case there are many more fields. Nevertheless, I also generated
a test case where the only field in the table is a varchar(8000). I
have run this test case on a machine with SQL Server 2005 Express and
it did work just fine. On another two systems with SQL Server 2000 it
failed. This seems to indicate that there is some issue with SQL
Server, though even 2000 should support 8000 chars. If you want email
me and I can send you the sample code.

Thanks
[quoted text, click to view]
John Bell
9/16/2006 12:45:01 AM
Hi

It seems that Steve's assessment of an unconvertable character at about the
length you get is the most probably reason. Use the UNICODE function to find
the integer value for these characters. It could be that word is stripping
these out

The maximum nvarchar size is 4000 so I would not expect greater than that,
but you may want to try converting to nvarchar to see if it is greater than
the 3900 using the datalength function.

John

[quoted text, click to view]
AddThis Social Bookmark Button