在尝试从MySQL数据库中获取数据时,在Qlikview中获取SQL错误

时间:2016-02-10 21:27:13

标签: mysql qlikview

我正在尝试使用MySQL数据源在QlikView中执行增量加载我得到的错误是

You have an error in your SQL syntax; check the manual that corresponds

我正在使用的脚本是

ODBC CONNECT TO Mysql_datasource_test;

 BKPF_TEMP:
LOAD 
//MANDT,
  BUKRS&GJAHR&BELNR AS KEY,
  BUKRS, //Company Code
  BELNR, //DocumentNo
  GJAHR, //YEAR
  BLART, //Document Type
  BLDAT, //Document Date
  BUDAT, //Posting Date
  MONAT, //Period
  CPUDT, //Entered on (To use this for the purpose of incremental load) 
  XBLNR, //Reference
  WAERS, //Currency
  KURSF  //Exchange rate
;
SQL SELECT *
FROM testtable.bkpf;
 where BLART IN ($(vDocTypes));

// Once data Initial data is loaded store the data in a QVD File
 Store BKPF_TEMP into $(vSaveQVD)BKPF_TEMP.QVD (QVD);


//// Load BKPF_TEMP QVD to get latest date updated..

 BKPF_TEMP:
 LOAD 
  //MANDT,
 KEY,
 BUKRS, //Company Code
 BELNR, //DocumentNo
 GJAHR, //YEAR
 BLART, //Document Type
 BLDAT, //Document Date
 BUDAT, //Posting Date
 MONAT, //Period
 CPUDT, //Entered on (To use this for the purpose of incremental load) 
 XBLNR, //Reference
 WAERS, //Currency
 KURSF  //Exchange rate
 FROM $(vSaveQVD)BKPF_TEMP.QVD (QVD);

// This step is to find the last updated date
BKPF:
LOAD *
Resident BKPF_TEMP
ORDER BY CPUDT;

// Looking at the last updated date
LET vUpdateDate = Peek('CPUDT',-1,'BKPF');

//// You Drop BKPF_TEMP because ordered data is already in BKPF table
DROP TABLE BKPF_TEMP;


ODBC CONNECT TO Mysql_datasource_test;
// Incremental load
BKPF_Incremental:
LOAD 
//MANDT,
   BUKRS&GJAHR&BELNR AS KEY,
BUKRS, //Company Code
BELNR, //DocumentNo
GJAHR, //YEAR
BLART, //Document Type
BLDAT, //Document Date
BUDAT, //Posting Date
MONAT, //Period
CPUDT, //Entered on (To use this for the purpose of incremental load) 
XBLNR, //Reference
WAERS, //Currency
KURSF  //Exchange rate
   ;

SQL SELECT *
   FROM testtable.bkpf
   where BLART IN ($(vDocTypes)) AND CPUDT >= $(vUpdateDate) ;

   //Concatinate incremental load with previously loaded records by adding new    records or replacing the updated records
   Concatenate
   LOAD 
  //MANDT,
   KEY,
   BUKRS, //Company Code
   BELNR, //DocumentNo
   GJAHR, //YEAR
   BLART, //Document Type
   BLDAT, //Document Date
   BUDAT, //Posting Date
   MONAT, //Period
   CPUDT, //Entered on (To use this for the purpose of incremental load) 
   XBLNR, //Reference
   WAERS, //Currency
   KURSF  //Exchange rate
   FROM $(vSaveQVD)BKPF_TEMP.QVD (QVD)
   Where not exists(KEY);

   STORE BKPF_Incremental into $(vSaveQVD)BKPF_TEMP.QVD (QVD);

   DROP TABLE BKPF_Incremental;

上有SQL错误
   SQL SELECT *
   FROM testtable.bkpf
   where BLART IN ($(vDocTypes)) AND CPUDT >= $(vUpdateDate) ;

我无法弄清楚这里有什么问题。

1 个答案:

答案 0 :(得分:3)

您需要将日期括在引号中,而不是

BLART IN ($(vDocTypes)) AND CPUDT >= $(vUpdateDate)

使用

BLART IN ($(vDocTypes)) AND CPUDT >= '$(vUpdateDate)'

QlikView对$(...)内的表达式进行文本替换,因此不会自行添加引号。