troubleshooting Question

SQL - Invalid Object within a subquery

Avatar of Zack
ZackFlag for Australia asked on
SQLMicrosoft SQL Server
7 Comments1 Solution15 ViewsLast Modified:
Hi EE,

For the following code, how would select data from the TAXTRANS TT table in the bold section of the SQL code below? Current the SQL engine is giving the error TT is an invalid object.

SELECT
      *
FROM (
      SELECT
           TT.TRANSDATE,
            TT.TAXAMOUNTCUR , TT.TAXORIGIN , TT.VOUCHER , TT.TAXITEMGROUP
          , TT.TAXCODE , TT.SOURCEBASEAMOUNTCUR , TT.SOURCETAXAMOUNTCUR
          , TTGJAERIVA.TAXTRANSRELATIONSHIP
          , TTGJAERIVA.GENERALJOURNALACCOUNTENTRY
          , TTGJAERIVA.LEDGERDIMENSION
          , GJAERIVA.TEXT
          , GJAERIVA.LEDGERDIMENSION AS LEDGERDIMENSIONGAE
          , GJAERIVA.POSTINGTYPE
      FROM TAXTRANS TT
      INNER MERGE JOIN TAXTRANSGENERALJOURNALACCOUNTENTRY TTGJAERIVA ON TTGJAERIVA.TAXTRANS = TT.RECID
      INNER MERGE JOIN GENERALJOURNALACCOUNTENTRY GJAERIVA ON TTGJAERIVA.GENERALJOURNALACCOUNTENTRY = GJAERIVA.RECID
            AND GJAERIVA.POSTINGTYPE IN (14, 236, 71, 41)
            AND TT.TRANSDATE >= '2016-10-10'
      WHERE (TT.TAXORIGIN <> 11
     AND TT.TRANSDATE BETWEEN '2017-10-10' AND '2017-12-15')
     OR (TT.TAXORIGIN = 11)
      -- AND TT.TRANSDATE BETWEEN '2017-10-20' AND '2017-10-25')
    ) AS T
LEFT MERGE JOIN (
      SELECT
            VOUCHER , SOURCERECID , TAXITEMGROUP , TAXCODE
          , GENERALJOURNALACCOUNTENTRY , TAXAMOUNT , TAXAMOUNTCUR
      FROM TT
    ) TTRISR ON T.VOUCHER = TTRISR.VOUCHER
          AND T.SOURCERECID = TTRISR.SOURCERECID
          AND T.TAXITEMGROUP = TTRISR.TAXITEMGROUP
          AND (TTRISR.TAXCODE LIKE 'R%')
          AND TTRISR.GENERALJOURNALACCOUNTENTRY = TTGJAE.GENERALJOURNALACCOUNTENTRY

Any assistance is appreciated.

Thank you. 
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros