September 12, 2011 at 9:22 am
Is it possible to do something like this?
Select column1 = @variable
From Table1;
Select *
From Table1
Where column2 = @variable
Do a select statement and return the one value to a variable. Turn around and do another select statement off the variable. In just a plain sql statement, not using a stored procedure?
September 12, 2011 at 9:23 am
That makes no sense. What are you trying to do?
September 12, 2011 at 9:30 am
The table I'm working with is kind of goofy. It has 2 ID fields.
Select strControlNbr From tblBonus Where intBonusID = @ID;
Select intBonusID From tblBonus Where strControlNbr = @strControlNbr
So I have BonusID for a specific row which is passed in from an application (@ID). I need to select the control number and then query the same table for all the IDs where the control number(strControlNbr) matches. The control number is replicated across anywhere from 1 to 6 rows.
September 12, 2011 at 9:34 am
goofy is a nice way to put it!
Select intBonusID From tblBonus Where strControlNbr IN (Select strControlNbr From tblBonus Where intBonusID = @ID)
September 12, 2011 at 9:41 am
Thank you for your help. I'm pretty new to using sql and haven't had much experiencewith subqueries. Totally forgot about that. Thank you again.
September 12, 2011 at 9:43 am
HTH, is strControlNbr nullable? If so you might be better off with a self join.
September 12, 2011 at 9:45 am
No it is not.
September 12, 2011 at 9:47 am
greg.fedder (9/12/2011)
No it is not.
Of then in will do the trick.
L8rs.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply