Greetings All, I have a very large query that uses dynamic sql. The
sql is very large and it requires it to be broken into three components
to avoid the nvarchar(4000) issue:
SET @v_SqlString(
N'')
SET @v_SqlString2(
N'')
SET @v_SqlString3(
N'')
The sql is large and I don't have a problem with that so I will not
post it. However, in the last string the very last statement looke
like:
SET @v_SqlString3(
N'
...
...
SELECT @v_TotalRowsLoa ded = @@ROWCOUNT, @v_ExitStat =
@@ERROR
')
I want to catch this output and I am having problems, here is what my
execute looks like:
EXEC('DECLARE @v_TotalRowsLoa ded integer
DECLARE @v_ExitStatus integer
EXEC sp_executesql N''' + @v_SqlString + @v_SqlString2 +
@v_SqlString3 + ''',
N''@v_TotalRows Loaded integer OUTPUT'',
@v_TotalRowsLoa ded OUTPUT,
N''@v_ExitStatu s integer OUTPUT'',
@v_ExitStatus OUTPUT,
N''@v_OLTPQuali fiedPath nvarchar(1000)' ',
@v_OLTPQualifie dPath = ''' + @v_OLTPQualifie dPath + ''',
N''@v_LoadTime datetime'', @v_LoadTime =
''' + @v_LoadTime + '''
'
)
When I run it as is I am prompted with:
Server: Msg 119, Level 15, State 1, Line 126
Must pass parameter number 8 and subsequent parameters as '@name =
value'. After the form '@name = value' has been used, all subsequent
parameters must be passed in the form '@name = value'.
You are required to pass five "5" arguments.
Can anyone tell me why this is failing? What can I do?
Any help would be greatly appreciated.
sql is very large and it requires it to be broken into three components
to avoid the nvarchar(4000) issue:
SET @v_SqlString(
N'')
SET @v_SqlString2(
N'')
SET @v_SqlString3(
N'')
The sql is large and I don't have a problem with that so I will not
post it. However, in the last string the very last statement looke
like:
SET @v_SqlString3(
N'
...
...
SELECT @v_TotalRowsLoa ded = @@ROWCOUNT, @v_ExitStat =
@@ERROR
')
I want to catch this output and I am having problems, here is what my
execute looks like:
EXEC('DECLARE @v_TotalRowsLoa ded integer
DECLARE @v_ExitStatus integer
EXEC sp_executesql N''' + @v_SqlString + @v_SqlString2 +
@v_SqlString3 + ''',
N''@v_TotalRows Loaded integer OUTPUT'',
@v_TotalRowsLoa ded OUTPUT,
N''@v_ExitStatu s integer OUTPUT'',
@v_ExitStatus OUTPUT,
N''@v_OLTPQuali fiedPath nvarchar(1000)' ',
@v_OLTPQualifie dPath = ''' + @v_OLTPQualifie dPath + ''',
N''@v_LoadTime datetime'', @v_LoadTime =
''' + @v_LoadTime + '''
'
)
When I run it as is I am prompted with:
Server: Msg 119, Level 15, State 1, Line 126
Must pass parameter number 8 and subsequent parameters as '@name =
value'. After the form '@name = value' has been used, all subsequent
parameters must be passed in the form '@name = value'.
You are required to pass five "5" arguments.
Can anyone tell me why this is failing? What can I do?
Any help would be greatly appreciated.
Comment