在mysql 5.5.25中使用的正确语法不存在

时间:2016-03-25 04:27:46

标签: mysql powerbuilder mysql-5.5

您好我试图在powerbuilder 12中写一个光标来获取一些记录。这是我的查询。 我试图从trninvhdr表中获取一些不在第二个表中的记录。

SELECT 
INV_DATE, 
INV_NO,
INV_TYPE,
CUR_CODE,   
EXCH_RATE,   
usd_rate,   
CR_TERM,   
DUE_DATE,   
bl_date, 
TOT_AMT 
FROM trninvhdr
WHERE 
COMP_CODE ='NFL1' AND 
CUST_CODE = 'NLML' AND 
INV_TYPE ='F' AND 
INV_DATE <= '2016-03-25' AND 
NOT EXISTS
 (SELECT * FROM trninvoiceavailability WHERE trninvoiceavailability.COMP_CODE = trninvhdr.COMP_CODE 
 AND trninvoiceavailability.INV_TYPE = trninvhdr.INV_TYPE AND trninvoiceavailability.INV_NO = trninvhdr.INV_NO);

这是我如何在程序中使用它。

DECLARE lc_retrieve CURSOR FOR

SELECT 
 trninvhdr.INV_DATE, 
 trninvhdr.INV_NO,
 trninvhdr.INV_TYPE,
 trninvhdr.CUR_CODE,   
 trninvhdr.EXCH_RATE,   
 trninvhdr.usd_rate,   
 trninvhdr.CR_TERM,   
 trninvhdr.DUE_DATE,   
 trninvhdr.bl_date, 
 trninvhdr.TOT_AMT 
FROM trninvhdr
WHERE 
COMP_CODE = :as_comp_code AND 
CUST_CODE = :as_cust_code AND 
INV_TYPE ='F' AND 
INV_DATE <= :as_inv_date )AND 
NOT EXISTS (SELECT * FROM trninvoiceavailability
 WHERE trninvoiceavailability.COMP_CODE = trninvhdr.COMP_CODE 
 AND trninvoiceavailability.INV_TYPE = trninvhdr.INV_TYPE AND
 trninvoiceavailability.INV_NO = trninvhdr.INV_NO);

     open lc_retrieve ;

查询在mysql服务器中工作正常,但在程序中它给了我以下错误。

数据库c0038 SQLSTATE = 3700 MySQL ODBC 5.2 a驱动程序mysql id 5.5.25您的语法有错误。检查与您的mysql版本对应的手册,以便在NOT EXISTS附近使用正确的语法(SELECT * FROM trninvoiceavailability ....在第1行。

我应该使用什么正确的语法来处理此查询。

2 个答案:

答案 0 :(得分:1)

您需要从查询中删除),如下所示 -

INV_DATE <= :as_inv_date )AND

sholuld INV_DATE <= :as_inv_date AND

答案 1 :(得分:1)

我可以在这段代码中看到一个括号......它来自哪里,它的朋友在哪里?

INV_DATE <= :as_inv_date )AND