I am trying to use the output of @strsql as one of the IF condition parameter for the second part of code. Once the conditions in IF satisfy it will execute the @strsql1 and give an output table. However the first query is running and giving an output of NULL and final output is missing with an error
'Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1 [Batch Start Line 0] Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
Am I wrong somewhere or if there is a better way to do it in a dynamic way. I have multiple conditions to pass and get a final output based on that. Basically second part of the code (@Sqlstr1) will run based on the output given by @strsql.
`DECLARE @ParmDefinition nvarchar(500);
DECLARE @max_title varchar(30); DECLARE @max_titleOUT varchar(30) begin
set @strsql = ' @max_titleOUT= Select OutTypeCode from vOption where TypeCode=''LOSS'' and ResultSID in (''' + replace(@Anlsids,',',''',''') + ''')' SET @ParmDefinition = @max_titleOUT
exec sp_executesql @strsql,@ParmDefinition, @max_titleOUT=@max_title OUTPUT;
SELECT @max_title
Declare @StrSQL1 nvarchar(max)
IF @Persp in ('POST') and @max_title in('EA')
set @StrSQL1 = ' Select
CountryName,
max( case when RP=10000 THEN num else 0 END)''10000'', max( case when RP=5000 THEN num else 0 END)''5000'', --------mode code )l )m group by CountryName order by AAL DESC'
Exec sp_executesql @StrSQL1
end`
Aucun commentaire:
Enregistrer un commentaire