September 8, 2006 at 1:05 pm
sp_executesql can only process 4000 characters, but my query exceeds more than 4000 characters. I don't have any parameter and I don't have any outout. So I tried to do the following
DECLARE @SQL1 NVARCHAR(4000), @SQL2 NVARCHAR(4000), @ReturnCode INT
SET @SQL1 = N'Insert into TABLEA SELECT .....'
SET @SQL2 = N'''A'' col1, ''B'' col2 FROM ftable1 WHERE...'
EXEC('EXEC sp_executesql N''' + @SQL1 + @SQL2 + '''')
I supposed to get a returncode from the query. I don't know how to do it in this way. Second it did not work, it kept saying something wrong in @SQL1.
I know I can use EXEC (@SQL) that will allow me to use 8000 characters but I need to find out the result of the query if it runs fine.
Can someone help me either using EXEC(@SQL) and get the status of the query or how to get sp_executesql to work?
Thanks
September 8, 2006 at 3:03 pm
Unfortunately I am using SQL Server 2000.
September 8, 2006 at 3:44 pm
This can allow upto 16000
declare @sql1 varchar(8000),
@sql2 varchar(8000),
@ret int
set @sql1=N'Select * from '
set @sql2=N'sysobjects;'
exec( @sql1 + @sql2)
I think you need to capture return code, that is not possible with this
September 9, 2006 at 1:28 pm
That is the reason why I need to use sp_executesql.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply