hey there, basically trying to get the [Field ID] saved into @fieldID so i can use it at another point in the SP. tried various combinations, but i mostly get errors of ‘Conversion failed when converting the varchar value … to data type int. The [field ID] is an int and primary key. i’ve even tried casting the [field id] just to make sure, it still fails.
Declare @fieldID as int
Declare @sql1 as varchar(1000)
set @sql1 = 'select '+@fieldID+' = [Field ID] from ['+@DataBaseName+'].dbo.[Custom Field Definition] where [Name] = ''Roster Y/N'' and [Table Type] = 0'
--print @sql1
exec(@sql1)
if i remove the ” ‘+@fieldID+’ ” i get the proper value back.
i know this doesn’t work, but is there something like, set @fieldID = exec(@sql1) ?
thanks for the help!
dave k.
you need to use SP_EXECUTESQL with OUTPUT
here is an example
So, try this