I have code part from trigger. When I test my trigger my exec doesn't return any data.
I declared my exec value as:
declare
@sql nvarchar(MAX),
@SQLString varchar(MAX)
and here is the select:
set @sql = N'select '
set @sql = @sql + '@SQLString = convert(varchar(1000),d.' + @fieldname + ')' +' + convert(varchar(1000),i.' + @fieldname + ')'
set @sql = @sql + ' from #ins i full outer join #del d'
set @sql = @sql + @PKCols --
set @sql = @sql + ' where i.' + @fieldname + ' <> d.' + @fieldname
set @sql = @sql + ' or (i.' + @fieldname + ' is null and d.' + @fieldname + ' is not null)'
set @sql = @sql + ' or (i.' + @fieldname + ' is not null and d.' + @fieldname + ' is null)'
(all variables work fine): like if I print @sql it will like this ->
select @SQLString = convert(varchar(1000), d.ActionID) + convert(varchar(1000), i.ActionID)
from #ins i
full outer join #del d on i.ActionID = d.ActionID
where i.ActionID <> d.ActionID
or (i.ActionID is null and d.ActionID is not null)
or (i.ActionID is not null and d.ActionID is null)
Here is execution:
EXEC sp_executesql @sql,
N'@SQLString varchar(MAX) OUTPUT',
@SQLString = @SQLString OUTPUT;
but print shows nothing:
print '@SQLString:' + @SQLString;