December 16, 2005 at 8:54 am
Hi
Does any one have an idea how to dynamically execute t-sql statement which is above 4000 Bytes(nvarchar) ?
As an example I have view which is more than 4000 Bytes (as test column of syscomments takes 2 rows), also some more select statements get appended to it over a period of time. so at this time i have to drop older one and create new view. Since view defination is more than 4000 Bytes i can't use nvarchar to store sql statement
Regards
Shrikant
Regards
Shrikant Kulkarni
December 16, 2005 at 7:28 pm
create a view from the SQL statement and then execute the view
SQL = Scarcely Qualifies as a Language
December 17, 2005 at 10:13 pm
Don't use sp_Execute. Just use EXEC...
EXEC (@SQL1+@SQL2+@SQL3....+@SQLn)
... and each of the variables can be VARCHAR(8000).
--Jeff Moden
Change is inevitable... Change for the better is not.
December 18, 2005 at 4:37 am
You can nest EXEC and sp_executesql
EXEC (N'EXEC sp_execuresql ' + @SQL1+ N', ' + @SQL2 + ', ' ...)
The query plan is then cached
You cab also use Varchar(MAX) and SQL 2005
December 18, 2005 at 8:14 am
Interesting... THAT allows you to use sp_ExecuteSQL with more than 4k bytes? I gotta try that.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 20, 2005 at 6:17 pm
would xp_execresultset work? Undocumented and Risky, but available.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply