Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

declare string that can hold more than 8000 characters in T-sql

Status
Not open for further replies.

dataforums

Programmer
May 3, 2005
25
0
0
US
Hi,

I need to declare a variable that can hold a string of more than 8000 characters. Like oracle provides LONG data type, does t-sql have an equivalent data type.

Thanks in advance
 
It does. TEXT and NTEXT columns.

You can find this and more info in Books On Line, by searching on "Data Types".

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks for the reply. I am actually trying to write a program in dyanmic SQL. I tried this earlier but it still gives me the following error:

Server: Msg 2739, Level 16, State 1, Line 1
The text, ntext, and image data types are invalid for local variables.
 
You can't have a local variable of text data type. Are you sure you need to use a dynamic SQL string that is more than 8000 characters? Could you split it up into smaller chunks?

--James
 

Thanks for the reply.

I am actually trying to build a a string to create a table dynamically that has more than 80 coulmns and this makes the string exceed the 8000 char limit with the varchar data type. In oracle, we use a LONG data type that can handle this, but i am not sure if there is any other data type in t-sql that can do this.
 
There isn't, if you are creating the query dynamically. You weill have to use two varchar(8000) variables and concatenate them at the end when you execute it.

Tim
 
You don't necessarily have to create a table with all 80 columns in it. You could create a table with the first 20 columns (or so) and then add columns to the table for the remaining columns.

Alter Table MyTable Add MyColumn(DataType)



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I will just concatenate the strings.

Thanks for all the replies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top