Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Assign variables to table columns at runtime

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2012-10-19 : 09:49:56
Hello,
how do i assign a variable to a table column at runtime

here is my code

thanks
M


select (select @to = receipient), (@from = senderid), (@msg = [message]) from histories where batch = @counter and username = 'school'


_____________________


Yes O !

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-19 : 10:00:57
The syntax is like shown below, BUT you have to be careful, because if the query returns more than one row, which value from among those will be assigned to your variable is indeterminate. So do this only when you are guaranteed that you will get only one row.
SELECT 
@to = receipient,
@from = senderid),
@msg = [message]
FROM histories
WHERE batch = @counter
AND username = 'school'
Go to Top of Page

mary_itohan
Posting Yak Master

191 Posts

Posted - 2012-10-19 : 18:04:22
ok many thanks

_____________________


Yes O !
Go to Top of Page
   

- Advertisement -