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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append to nText

Status
Not open for further replies.

dky1e

Programmer
May 4, 2002
293
0
0
US
Hi, I need help!

I need to use a local variable of length greater than 4k characters. The only way to accomplish this is to use the nText field (I need nText because i'm buildig a dynamic string for a query that will be then executed by sp_executesql).

Since i cant declare an ntext variable I had to create a temp table that stores this value. Now, I have a loop that needs to append to the value stored in the nText field.

Is it possible?


-----
What would be a better solution?

 
What front end are you using to store this 4k value?
 
Have you tried using string?

I have built 4k strings before and then call exec(string)
 
SQL Server. There is not a String data type.
 
if this is any help, the varchar datatype goes up to 8000 characters

 
You could try putting parts of the string into different variables (one for the columns, one for the joins, one for the where clause, one for the group on clause, etc.) and then concatenating them together to execute. But honestly how many SQL strings are more than 8000 characters? We have a search with 30 different possible input values and 5 related tables and our search strings never get that long.
 
Couold you use something like the following?

Create uspYourProcName
@sql1 nvarchar(4000),
@sql2 nvarchar(4000),
@sql3 nvarchar(4000)
As

exec ('sp_executesql @statement=N'''+@sql1+@sql2+@sql3+'''') If you want to get the best answer for your question read faq183-874 and faq183-3179.
Terry L. Broadbent - DBA
SQL Server Page:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top