Select column1 = new @var; Select * Where ID = @var; Possible?

  • 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?

  • That makes no sense. What are you trying to do?

  • 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.

  • goofy is a nice way to put it!

    Select intBonusID From tblBonus Where strControlNbr IN (Select strControlNbr From tblBonus Where intBonusID = @ID)

  • 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.

  • HTH, is strControlNbr nullable? If so you might be better off with a self join.

  • No it is not.

  • 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