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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL query error

Status
Not open for further replies.

rchinoy

Programmer
Oct 18, 2002
2
US
I'm using the query:

--------------------------------------
SELECT ORD_ID, RETURN_ReqDate, MAX(ReturnItems.RETSTAT_ID) AS MaxRetItemStatusID, COUNT(RETITEM_ID) AS RETURN_ItemCount
FROM Returns, ReturnItems
WHERE (Returns.CUST_ID = #Session.CUST_ID#) AND (ReturnItems.RETURN_ID=Returns.RETURN_ID)
GROUP BY ORD_ID, RETURN_ReqDate
ORDER BY RETURN_ReqDate DESC
--------------------------------------

And getting the error:

--------------------------------------
ODBC Error Code = 42000 (Syntax error or access violation)


[TCX][MyODBC]You have an error in your SQL syntax near 'Returns, ReturnItems WHERE (Returns.CUST_ID = 1) AND (ReturnItems.RETURN_ID=Ret' at line 2


SQL = "SELECT ORD_ID, RETURN_ReqDate, MAX(ReturnItems.RETSTAT_ID) AS MaxRetItemStatusID, COUNT(RETITEM_ID) AS RETURN_ItemCount FROM Returns, ReturnItems WHERE (Returns.CUST_ID = 1) AND (ReturnItems.RETURN_ID=Returns.RETURN_ID) GROUP BY ORD_ID, RETURN_ReqDate ORDER BY RETURN_ReqDate DESC"
--------------------------------------

This works perfectly well in SQL Server, but obviously not in MySQL. Any idea what the problem is?

Thanks,
Russ
 
Never mind. I just did a search of the mySQL docs and found that "Returns" (one of my table names) is a reserved word. I changed the table name and I'm changing my code now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top