Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 execute a dynamically build sql string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-01-21 : 08:09:23
Clemens writes "I want to execute a dynamically build sql string. The sql string can exceed 8000 characters. This means that I cannot use a local variable, because text variables are not allowed. I thought about using a temp table, or table variable. Does anyone know how to execute a string that exceeds 8000 characters.

Thanks in advance,
Clemens."

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-01-21 : 08:14:12
I doubt it very much. 8k is a very long command to execute, why not cut it into smaller chunks and execute, within a batch if necessary to ensure all chunks execute or none at all.


Raymond
Go to Top of Page

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2004-01-21 : 08:15:51
How about creating a temp table with a TEXT column and build up the text in there? No idea if that's even possible, just thinking out loud.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-01-21 : 23:06:00
It's possible, but you won't be able to assign the value to a text variable, so it won't be executable.

There is an undocumented procedure called xp_execresultset that can execute SQL statements stored in a table, BUT...it is kind of flaky and can cause serious problems if not used carefully (I locked up a production server with it once) There's some discussion about it here:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13384

But I'd strongly recommend against using it, unless you can safely and thorougly test it. You'd be better off using multiple varchar variables like Raymond suggested.
Go to Top of Page
   

- Advertisement -