cooking
asked on
MSSQL how to get value from table into variable ?
hi .. let's say i have a table and a variable.
SELECT email from parent where username = @pusername;
will return the value that i need to have in @mail variable..
how can i set the @mail variable to get the value of the above sql query ? i also know that it will return only one result .
thanks in advance
SELECT email from parent where username = @pusername;
will return the value that i need to have in @mail variable..
how can i set the @mail variable to get the value of the above sql query ? i also know that it will return only one result .
thanks in advance
you are sure about that your query will return only one value so there is no problem at all, since there is no concept like array in SQL Server so if your query will return more than one row in above query, only last email address will be stored in @mail variable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
generally in the situation Author has, I would go for SELECT not for SET, nothing much different but just wanted to stick with ANSI standard, basically SET is used to assign static value and SELECT is for getting value in variable from QUERY. have a look.
http://www.sqlhub.com/2009/03/set-and-select-in-sql-server-2005.html
http://www.sqlhub.com/2009/03/set-and-select-in-sql-server-2005.html
select @mail=email from parent where username=@parentname
select @mail