BIRT SQL 空案例场景
BIRT SQL Null Case Scenario
我正在使用以下 SQL 语句来检索有关工单的各种信息。但是,其中一些没有列出资产 (NULL),在这种情况下,我得到 0 行:
select PM17, WORKORDER.PMNUM, WORKORDER.ASSETNUM, ASSET.DESCRIPTION, ASSET.MANUFACTURER, EQASSETNUM, WORKORDER.LOCATION, LOCATIONS.DESCRIPTION, PM.ROUTE, TARGSTARTDATE, TARGCOMPDATE, PM.NEXTDATE
from WORKORDER
JOIN ASSET ON WORKORDER.ASSETNUM = ASSET.ASSETNUM
JOIN PM ON WORKORDER.PMNUM = PM.PMNUM
JOIN LOCATIONS ON WORKORDER.LOCATION = LOCATIONS.LOCATION
WHERE WORKORDER.WONUM='1011';
如何修改我的声明以适用于这两种情况(有或没有 ASSETNUM)?
案例 1 (ASSETNUM != NULL)--> 显示所有选择的字段
案例 2 (ASSETNUM = NULL) --> 显示不依赖于 ASSETNUM 的字段,returns 其余字段为空
将您的 JOIN
更改为 LEFT JOIN
:
select PM17, WORKORDER.PMNUM, WORKORDER.ASSETNUM, ASSET.DESCRIPTION, ASSET.MANUFACTURER, EQASSETNUM, WORKORDER.LOCATION, LOCATIONS.DESCRIPTION, PM.ROUTE, TARGSTARTDATE, TARGCOMPDATE, PM.NEXTDATE
from WORKORDER
LEFT JOIN ASSET ON WORKORDER.ASSETNUM = ASSET.ASSETNUM
JOIN PM ON WORKORDER.PMNUM = PM.PMNUM
JOIN LOCATIONS ON WORKORDER.LOCATION = LOCATIONS.LOCATION
WHERE WORKORDER.WONUM='1011';
我正在使用以下 SQL 语句来检索有关工单的各种信息。但是,其中一些没有列出资产 (NULL),在这种情况下,我得到 0 行:
select PM17, WORKORDER.PMNUM, WORKORDER.ASSETNUM, ASSET.DESCRIPTION, ASSET.MANUFACTURER, EQASSETNUM, WORKORDER.LOCATION, LOCATIONS.DESCRIPTION, PM.ROUTE, TARGSTARTDATE, TARGCOMPDATE, PM.NEXTDATE
from WORKORDER
JOIN ASSET ON WORKORDER.ASSETNUM = ASSET.ASSETNUM
JOIN PM ON WORKORDER.PMNUM = PM.PMNUM
JOIN LOCATIONS ON WORKORDER.LOCATION = LOCATIONS.LOCATION
WHERE WORKORDER.WONUM='1011';
如何修改我的声明以适用于这两种情况(有或没有 ASSETNUM)?
案例 1 (ASSETNUM != NULL)--> 显示所有选择的字段
案例 2 (ASSETNUM = NULL) --> 显示不依赖于 ASSETNUM 的字段,returns 其余字段为空
将您的 JOIN
更改为 LEFT JOIN
:
select PM17, WORKORDER.PMNUM, WORKORDER.ASSETNUM, ASSET.DESCRIPTION, ASSET.MANUFACTURER, EQASSETNUM, WORKORDER.LOCATION, LOCATIONS.DESCRIPTION, PM.ROUTE, TARGSTARTDATE, TARGCOMPDATE, PM.NEXTDATE
from WORKORDER
LEFT JOIN ASSET ON WORKORDER.ASSETNUM = ASSET.ASSETNUM
JOIN PM ON WORKORDER.PMNUM = PM.PMNUM
JOIN LOCATIONS ON WORKORDER.LOCATION = LOCATIONS.LOCATION
WHERE WORKORDER.WONUM='1011';