在查询结果列表中插入默认值

时间:2016-04-24 11:21:12

标签: sql birt

我必须更改查询,并希望在两个不同的列上找到两个值时向查询添加一些预定义的结果(输出)。

基本上我想在查询的新列中添加值。我尝试使用CASE但直到现在都没有运气。

SELECT DISTINCT
Q1.SCHD_ID,
Q1.SCHD_DESC,
Q1.TIMEZONE_ID,
Q1.DISPLAY_IN_SCHD_TZ,
Q1.LOGO_ID,
Q1.CODICE_SKOFF,
Q1.CODICE_MODULO,
case
when (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '2346') THEN 'testA'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '2347') THEN 'testB'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '3287') THEN 'testC'
WHEN (Q1.PIANO_CODICE = 'FND001' AND Q1.CODICE_SKOFF = '0000') THEN 'testD'
WHEN (Q1.PIANO_CODICE = 'TEST' AND Q1.CODICE_SKOFF = '4435') THEN 'testE'
ELSE 'NULL'
END as TITOLO_MODULO_SO

FROM

(SELECT
  sc.SCHD_ID, 
  sc.SCHD_DESC,
  sc.TIMEZONE_ID,
  sc.DISPLAY_IN_SCHD_TZ,
  SUBSTR(su1.USER_VALUE, 1 ,3) as LOGO_ID,
  su1r.USER_DESC as PIANO_FINANZIAMENTO,
  su1r.USER_ID as PIANO_CODICE,
  cu1.USER_VALUE as TITOLO_MODULO,
  cu2.USER_VALUE as CODICE_MODULO,
  c.CPNT_TITLE as ARGOMENTO,
  sr.START_DTE,
  sr.END_DTE,
  cu3.USER_VALUE as DURATA_CORSO,
  su4.USER_VALUE as CODICE_SKOFF
   FROM PA_SCHED sc
-- Campo "Piano principale di finanziamento"
left outer join PA_SCHED_USER su1 on sc.SCHD_ID = su1.SCHD_ID and su1.COL_NUM = 50
left outer join PA_USRRF_SCHED su1r on su1r.COL_NUM = su1.COL_NUM and su1.USER_VALUE = su1r.USER_ID
-- Informazioni ITEM
left outer join PA_CPNT c on c.CPNT_TYP_ID = sc.CPNT_TYP_ID and c.CPNT_ID = sc.ACT_CPNT_ID and c.REV_DTE = sc.REV_DTE
-- ITEM -> Titolo per finanziamenti
left outer join PA_CPNT_USER cu1 on cu1.CPNT_TYP_ID = c.CPNT_TYP_ID and cu1.CPNT_ID = c.CPNT_ID and cu1.REV_DTE = c.REV_DTE and cu1.COL_NUM = 10
-- ITEM -> Codice Finanziamento
left outer join PA_CPNT_USER cu2 on cu2.CPNT_TYP_ID = c.CPNT_TYP_ID and cu2.CPNT_ID = c.CPNT_ID and cu2.REV_DTE = c.REV_DTE and cu2.COL_NUM = 100
-- ITEM -> Ore finanziamento
left outer join PA_CPNT_USER cu3 on cu3.CPNT_TYP_ID = c.CPNT_TYP_ID and cu3.CPNT_ID = c.CPNT_ID and cu3.REV_DTE = c.REV_DTE and cu3.COL_NUM = 90
-- Dati della Scheduled Offering
left outer join PS_SCHD_RESOURCES sr on sr.SCHD_ID = sc.SCHD_ID
-- Facility
left outer join PA_FACILITY f on f.FACILITY_ID = sc.FACILITY_ID
-- Location
left outer join PA_LOCN l on l.LOCN_ID = sr.LOCN_ID
-- Campo "Banca capofila"
left outer join PA_SCHED_USER su3 on sc.SCHD_ID = su3.SCHD_ID and su3.COL_NUM = 10
left outer join PA_USRRF_SCHED su3ref on su3ref.COL_NUM = su3.COL_NUM and su3ref.USER_ID = su3.USER_VALUE
-- Campo "Multisocietario"
left outer join PA_SCHED_USER su2 on sc.SCHD_ID = su2.SCHD_ID and su2.COL_NUM = 30
-- Campo "Codice Finanz. SKOFF"
left outer join PA_SCHED_USER su4 on sc.SCHD_ID = su4.SCHD_ID and su4.COL_NUM = 99

 ) q1

哪种方法最好?

dbms IS birt 我对查询的临时表有用吗?

谢谢

0 个答案:

没有答案