Assigning a variable from a select...

Results 1 to 2 of 2

Thread: Assigning a variable from a select...

  1. #1
    Join Date
    Dec 1969

    Default Assigning a variable from a select...

    I am needing to get the record IDs from a select statement and then reuse it in a nested SELECT statement. The first SELECT should give many records. I have constructed an example (below) of what I am doing. Don&#039;t look too deep into the example but you can see I am attempting to use the &#039;@ID&#039; as my variable. Is this a proper method to use or what would be a better way of getting results from a second SELECT when a JOIN just won&#039;t work?<BR><BR>SELECT tbl1.GroupID AS @ID<BR>(<BR>SELECT Count(*), <BR>FROM tbl2 INNER JOIN<BR>tbl3 ON tbl2.RegionID = tbl3.RegionID<BR>WHERE (tbl3.Active = 1) AND (tbl2.GroupID = @ID)<BR>)<BR>FROM tbl1<BR>GROUP BY tbl1.GroupID<BR>HAVING (tbl1.Active = 1)<BR><BR><BR>Thanks,<BR><BR>Neighborkid

  2. #2
    Join Date
    Dec 1969

    Default I think this what you are looking

    for<BR><BR>SELECT Count(*)<BR>FROM tbl2, tbl3 <BR>WHERE tbl2.RegionID = tbl3.RegionID <BR>AND tbl3.Active = 1 <BR>AND tbl2.GroupID IN <BR> (SELECT distinct tbl1.GroupID<BR> FROM tbl1 <BR> WHERE tbl1.Active = 1)<BR><BR>Good luck<BR>Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts