[dba-SQLServer] Assign Select to local variable

David Emerson newsgrps at dalyn.co.nz
Sun Aug 2 16:32:42 CDT 2009


I have a table full of field names.  Having selected a field name I 
would like to put the value of the field into a local variable.

Here is my code so far:

SELECT @FieldName = FieldName FROM @tblFieldList WHERE ID = @FieldListID

SET @qry = 'SELECT ' + @FieldName + ' FROM dbo.tblBWSClient WHERE 
BWSClientID = ' + CAST(@BaseLineRevisionID AS varchar(20))
EXEC @qry

This gives me the value of the @FieldName field.  How can I store 
this value in a variable called @OldValue?




More information about the dba-SQLServer mailing list