How do I pass and use the column name to retrieve a bigint variable in the actual column?
DECLARE @personID BIGINT,
DECLARE @queryString varchar(500)
Set @queryString = 'Select @personID = ' + @PersonColumnID + ' from dbo.Loss_Witness where WitnessID = @witnessID'
exec(@queryString)
Error message states "Must declare variable '@personID'." I also tried
Set @queryString = 'Select ' + @personID + ' = ' + @witnessPersonID + ' from dbo.Loss_Witness where WitnessID = @witnessID'
And got the error message "Error converting data type varchar to bigint."
Any thoughts?