Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error in query expression

Status
Not open for further replies.

svsuthar1

Programmer
Jul 6, 2004
135
US
I have the following error please help identify what it is...

Syntax error in query expression '(((tblCategory.fldCategoryID)=4 AND ((tblInventoryData.fldActionID)=2));'


Here is my SQL

strSQL ="SELECT fldProductName, Sum(IIf(DatePart(""m"",[fldDate])=1,[fldQuantity],0)) AS Jan, Sum(IIf(DatePart(""m"",[fldDate])=2,[fldQuantity],0)) AS Feb, " _
& "Sum(IIf(DatePart(""m"",[fldDate])=3,[fldQuantity],0)) AS Mar, Sum(IIf(DatePart(""m"",[fldDate])=4,[fldQuantity],0)) AS Apr, Sum(IIf(DatePart(""m"",[fldDate])=5,[fldQuantity],0)) AS May, " _
& "Sum(IIf(DatePart(""m"",[fldDate])=6,[fldQuantity],0)) AS Jun, Sum(IIf(DatePart(""m"",[fldDate])=7,[fldQuantity],0)) AS Jul, Sum(IIf(DatePart(""m"",[fldDate])=8,[fldQuantity],0)) AS Aug, " _
& "Sum(IIf(DatePart(""m"",[fldDate])=9,[fldQuantity],0)) AS Sep, Sum(IIf(DatePart(""m"",[fldDate])=10,[fldQuantity],0)) AS Oct, Sum(IIf(DatePart(""m"",[fldDate])=11,[fldQuantity],0)) AS Nov, Sum(IIf(DatePart(""m"",[fldDate])=12,[fldQuantity],0)) AS [Dec] " _
& "FROM (tblCategory INNER JOIN tblProducts ON tblCategory.fldCategoryID = tblProducts.fldCategoryID) INNER JOIN tblInventoryData ON tblProducts.fldProductID = tblInventoryData.fldProductID " _
& "GROUP BY tblCategory.fldCategoryID, tblProducts.fldProductName, tblInventoryData.fldActionID " _
& "HAVING (((tblCategory.fldCategoryID)=" & Request.QueryString("CategoryID") & " AND ((tblInventoryData.fldActionID)=2));
 
Short a parenthesis

'((
(tblCategory.fldCategoryID)=4)
AND
((tblInventoryData.fldActionID)=2));'

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Try removing one of the opening paranthesis. Like this:
Code:
((tblCategory.fldCategoryID)=4 AND ((tblInventoryData.fldActionID)=2));

------------------------------------------------------------------------------------------------------------------------
If you don't have a sense of humor, you probably don't have any sense at all.
- Anonymous
 
It's also worth noting that things like (tblCategory.fldCategoryID) don't need that set of parentheses, nor do the individual = items, nor does the HAVING clause (I don't believe). You could make it MUCH easier to debug by eliminating all of your parentheses.
Code:
  & "HAVING (((tblCategory.fldCategoryID)=" & Request.QueryString("CategoryID") & " AND ((tblInventoryData.fldActionID)=2));"
becomes
Code:
  & "HAVING tblCategory.fldCategoryID=" & Request.QueryString("CategoryID") & " AND tblInventoryData.fldActionID=2;"
At the VERY worst it could definitely be:
Code:
  & "HAVING (tblCategory.fldCategoryID=" & Request.QueryString("CategoryID") & " AND tblInventoryData.fldActionID=2);"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top