我正在努力将我放在一起的这两个语句组合成一个语句。
我的第一个语句实际上是 3 个语句,其中我只希望第一个返回值的语句被返回,这是一种享受。
SELECT ReferenceKey, ReferenceValue FROM
(
SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '|| b.BANM11 AS ReferenceValue, 1 as preference
FROM THTFU.THAP076P AS a LEFT OUTER JOIN OSLTHLF3.CSP11 AS b ON b.BANK11 = a.GBNK076 AND b.CONO11 = a.CONO076
WHERE a.CONO076 = '01' AND a.PMTH076 = 'BMG' AND a.CURN076 = 'EUR'
UNION
SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '|| b.BANM11 AS ReferenceValue, 3 as preference
FROM THTFU.THAP076P AS a LEFT OUTER JOIN OSLTHLF3.CSP11 AS b ON b.BANK11 = a.GBNK076 AND b.CONO11 = a.CONO076
WHERE a.CONO076 = '01' AND a.PMTH076 = 'BMG' AND a.CURN076 = ''
UNION
SELECT a.GBNK076 AS ReferenceKey, TRIM(a.GBNK076) ||' - '|| b.BANM11 AS ReferenceValue, 3 as preference
FROM THTFU.THAP076P AS a LEFT OUTER JOIN OSLTHLF3.CSP11 AS b ON b.BANK11 = a.GBNK076 AND b.CONO11 = a.CONO076
WHERE a.CONO076 = '01' AND a.PMTH076 = '' AND a.CURN076 = ''
)BankPayingFrom ORDER BY preference
FETCH FIRST 1 ROWS ONLY
但是,如果这三个语句都没有返回任何信息,我希望能够触发下面的 SQL 语句来检索所有可能的记录。
SELECT BANK11 as ReferenceKey, TRIM(BANK11) ||' - '|| BANM11 as ReferenceValue From OSLTHLF3.CSP11 WHERE CONO11 = '01'
如何将这两个语句连接在一起,以便我只需从我的 Web 服务调用一次后端数据库(AS/400 DB2 数据库)?
我会很感激任何帮助。
非常感谢克里斯蒂安