Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2012
    Location
    Logan, Utah
    Posts
    163

    Unanswered: Proper Place for a Sub Select

    I have a very simple query that gets a field to use as constraints in another query.

    Code:
    SELECT A.RIN
      FROM apcType T
     INNER JOIN  apcAttribute a on A.T = T.RIN
     WHERE T.Name like '%Sales'
    The results of the first query are used in the following query where it is bolded and marked with and <<<<========

    Code:
    SELECT AP.Arg2, AP.Arg3,  M.Parcel, 
          M.Serial, M.Name, M.Acres, M.District,  
          V.YearBuilt, V.Code, V.Size,  
          (SELECT SUM(V1.Acres) 
             FROM TRValue V1 
            WHERE V1.Year = V.Year and V1.Parcel = V.Parcel and 
                     SUBSTRING(V1.Code, 1, 1) = 'L'
          )  
      FROM TRValue V 
     INNER JOIN APList AP on AP.TRValueRIN = V.RIN 
     INNER JOIN TRMaster M on M.Year = V.Year and M.Parcel = V.Parcel 
     WHERE M.Year = 2012 and M.Deleted = 0 
              and M.Parcel between '00-0000-0012' and '00-9999-9999' 
              and M.District between 1 and 98 
              and AP.Arg2 between 76340 and 77770 
              and AP.AttributeRIN in (1900,1901) --<<<<=========
     ORDER BY M.Parcel
    My question is How can I fold the first query into the second?

  2. #2
    Join Date
    Dec 2012
    Location
    Logan, Utah
    Posts
    163

    Solved!

    As is the case, it seems that I have figured it out after posting a question.

    Putting the first select statement into the where clause seemed to do the trick.

    The modified 2nd query simply becomes:

    Code:
    and AP.AttributeRIN in 
       (SELECT A.RIN
          FROM apcType T
         INNER JOIN apcAttribute a on A.T = T.RIN
         WHERE T.Name like '%Sales')

Posting Permissions

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