系统绑定变量
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Local string &strSqlBasNum = "%SELECTALL(:1 BASNUM) WHERE C_SB_BUY_COMPANY IN (" | &strCompanyMu | ") AND EFFDT BETWEEN %DateIn('" | &dtPRD_BGN_DT | "') AND %DateIn('" | &dtPRD_END_DT | "') AND %EFFDTCHECK(:1 BASNUM2,BASNUM,'" | &dtPRD_END_DT | "')"; Local SQL &SQLBasNum = CreateSQL(&strSqlBasNum, Record.C_SB_BASNUM_TBL);
SQLExec(" SELECT B.EFFDT,B.EFF_STATUS,B.C_SB_PAY_STATUS,B.C_SB_BUY_COMPANY,B.C_SB_JF_COMPANY,B.C_GP_PAY_TYPE,B.C_SB_LOC_ID,B.C_SB_RULE_ID,B.C_ENDO_INSU,B.C_IS_SBCALC FROM PS_C_SB_BASNUM_TBL B WHERE B.EMPLID =:1 AND B.EFFDT = (SELECT MAX(B1.EFFDT) FROM PS_C_SB_BASNUM_TBL B1 WHERE B1.EMPLID = B.EMPLID AND B1.EFFDT < %DateIn('" | &rec_C_SB_BASNUM_TBL.EFFDT.Value | "'))", &rec_C_SB_BASNUM_TBL.EMPLID.Value, &arrBaseInfo); local string &sqlTest = "select "| Quote(&emplId) |" from ps_job "; local string &sqlTest = "select "| &emplId |" from ps_job ";
|
注意事项
1.通过SQLExec插入或更新long类型的字段,当值超过254个字符时,会出现 Bind value is too long错误。
解决方案:
使用%TextIn(BindVariable) 函数,即可对longChar类型字段进行更新和插入。
1 2 3
| &String1 = "This is a test." ;
SqlExec("INSERT INTO PS_TABLE1 (STMTID, SQLSTMT) VALUES (1, %TextIn(:1))", &String1);
|
2.如果字段内储存了英文的单引号 ‘ 在进行SQL拼接时,会出现SQL ERROR。
解决方案:
使用转移符号 ,即在英文的单引号前面加一个英文的单引号 ‘’
1 2 3 4 5
| &name1 = C_PRH_SER_WK.NAME1.Value; If All(&name1) Then rem 替换函数,讲一个英文单引号替换为两个英文单引号; &name1 = Substitute(&name1, "'", "''"); End-If;
|