我需要根据IIB / WMB输入xml中给出的Job代码从两个表中检索数据。
SQL查询
SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM DEPT D JOIN EMP E on E.JOB ='MANAGER' OR E.JOB = 'CLERK'
ESQL查询
从输入xml获取JOB详细信息并将其分配给本地变量。
SET type1 = InputRoot.XMLNSC.Employee.Type[1];
SET type2 = InputRoot.XMLNSC.Employee.Type[2];
现在我需要将上述变量传递给我的ESQL查询。
SET Outputroot.XMLNSC.List[] = PASSTHRU('SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM Database.EMP AS E,Database.DEPT AS D where E.JOB =?' VALUES('type1','type2')) ;
但上述查询无效。
答案 0 :(得分:2)
此查询中存在两个问题:
首先,您传递的是两个参数,但查询中只存在一个问号(?)。
其次,您传递的字符串值类似于'type1',正确的是传递变量:
SET Outputroot.XMLNSC.List[] = PASSTHRU('SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM Database.EMP AS E,Database.DEPT AS D where E.JOB =?' VALUES(type1)) ;
答案 1 :(得分:1)
以下是解决方案:
DECLARE designation char;
DECLARE designation1 char;
DECLARE Query char;
FOR source AS InputRoot.XMLNSC.Employees.Designation[] DO
IF(source = '') THEN
SET designation = 'Empty';
ELSE
SET designation = designation1 ||''''||UPPER(source)||'''';
SET designation1 = ''''||UPPER(source)||''''||','||designation1 ;
END IF;
SET Query = '(SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM EMP AS E JOIN DEPT AS D on D.DEPTNO = E.DEPTNO where E.JOB in ('||designation||'))';
SET Outputroot.XMLNSC.List[] = PASSTHRU(Query);
答案 2 :(得分:0)
在PASSTHRU语句后添加To Database.DBName
,其中DBName是您的数据库名称
像这样:
SET Outputroot.XMLNSC.List[] = PASSTHRU('SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM Database.EMP AS E,Database.DEPT AS D where E.JOB =?' VALUES(type1)) To Database.DBName ;
答案 3 :(得分:0)
passthru call应该是
SET Outputroot.XMLNSC.List[] = PASSTHRU('SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM Database.EMP AS E,Database.DEPT AS D where E.JOB in (? , ?)', type1,type2) ;
OR
SET Outputroot.XMLNSC.List[] = PASSTHRU('SELECT D.DEPTNO,D.DNAME,D.LOC,E.EMPNO,E.ENAME,E.JOB,E.SAL FROM Database.EMP AS E,Database.DEPT AS D where E.JOB=? or E.JOB=?)', type1,type2) ;