Link to home
Start Free TrialLog in
Avatar of allelopath
allelopath

asked on

Assign result set to scalar?

I have a standard procedure where  MyNumber is passed in as a parameter.
Using it, I want to get the value of tblMyTable.MyId and assign it to @MyId
How do I do this?
 
DECLARE @Myid as int
select [Myid] from [MyDB].[dbo].[tblMyTable]
where [MyNumber] = @MyNumber
-- @MyId = [Myid] ???
-- use @Myid at this point

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bhavesh Shah
Bhavesh Shah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have two variables used in your query, @Myid and @MyNumber. If you want to select from the table based on the passed-in variable only, then you don't need both.

DECLARE @MyNumber INT
SET @MyNumber = 12345

SELECT MyID, col1, col2, ..... FROM MyTable
WHERE MyID = @MyNumber

Open in new window