SQLTeam.com | Weblogs | Forums

SQL Query error


#1

Hi,
I created the query below but I am receiving the following error when I execute the query:

Msg 102, Level 15, State 1, Line 30
Incorrect syntax near 'D6'.

Before I execute, I receive the message "An expression of non-Boolean type specified in a context where a condition is expected".

What am I doing wrong ?

SELECT DOCDATE, VENNAME, ITEM, ADDRESS1, PONUM, APPROVEDBY, APPROVALDATE, TOTAL, TAX, VENDORDOCNO
FROM
(SELECT P1.DOCDATE AS DOCDATE, P1.VENDNAME AS VENNAME, P2.ITEMDESC AS ITEM, P1.PONUMBER AS PONUM,
P1.SUBTOTAL AS TOTAL, P1.TAXAMNT AS TAX
FROM
POP10100 P1
INNER JOIN POP10110 P2
ON P1.PONUMBER = P2.PONUMBER)D1
LEFT OUTER JOIN
(SELECT P4.POA_Approved_By AS APPROVEDBY, P4.APPRVLDT AS APPROVALDATE
FROM
POA40003 P4
INNER JOIN POP10100 P1 ON P4.PONUMBER = P1.PONUMBER)D2

                  INNER JOIN 
				  
				  (SELECT P3.ADDRESS1 AS ADDRESS1
				  FROM IV40700 P3
				  INNER JOIN POP10110 P8
				  ON P8.LOCNCODE = P3.LOCNCODE)D3
				 
				   INNER JOIN
                  
				  (SELECT P9.POPRCTNM AS RECEIPTNO
				   FROM POP30310 P9 INNER JOIN POP10110 P10
				   ON P9.PONUMBER = P10.PONUMBER AND P9.ITEMNMBR = P10.ITEMNMBR AND P9.LOCNCODE = P10.LOCNCODE)D4
				   INNER JOIN
                  (SELECT P11.VNDDOCNM AS VENDORDOCNO 
				  FROM POP30300 P11 INNER JOIN POP30300 P12
				  ON P11.POPRCTNM = P12.POPRCTNM)D6

#2

you are missing all the JOIN ON condition in the derived table

FROM
(
   < query >
) D1
LEFT JOIN
(
  < query >
) D2   ON     D1.some_column = D2.another_column