[dba-SQLServer] Assign Select to local variable

Bobby Heid bheid at sc.rr.com
Sun Aug 2 16:42:51 CDT 2009


David,

If I understand your question correctly, after running the exec, all you
have to do is:

SET @OldValue = @FieldName

Bobby


-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of David
Emerson
Sent: Sunday, August 02, 2009 5:33 PM
To: dba-SQLServer at databaseadvisors.com
Subject: [dba-SQLServer] Assign Select to local variable

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?

_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com






More information about the dba-SQLServer mailing list