I am trying to insert the result of a dynamic SQL query into a table. I need to convert the result to int but my code is trying to convert the dynamic SQL string to int (i.e. error converting 'select appid...') instead of the value returned by the query.
I submit this to the experts. Please help!
Code:
declare @fieldnm nvarchar(5), @value nvarchar(100)
set @fieldnm = 'd' + @dept
set @value = 'Select appid from secapp where ' + @fieldnm + ' = 1'
[b]exec(@value)[/b]
insert into secappuser( appid, uid, dateadded, enabled)
values ( [b]convert(int, @value)[/b], @uid, getdate(), 1)
I submit this to the experts. Please help!