我有以下SQL语句:
SELECT
WORKORDER.WONUM,
WORKORDER.WO3,
WORKORDER.DESCRIPTION WO_DESC,
WORKORDER.WORKTYPE,
WORKORDER.STATUS,
WORKORDER.WOPRIORITY,
(case when WORKORDER.CUSTREQ1=1 then 'Yes' else 'No' end) WO18,
WORKORDER.REPORTDATE,
WORKORDER.ACTFINISH,
(WORKORDER.LOCATION + ' ' +LOCATIONS.DESCRIPTION) LOC_DESC
FROM WORKORDER
LEFT OUTER JOIN LOCATIONS ON WORKORDER.LOCATION = LOCATIONS.LOCATION
WHERE
WORKORDER.HISTORYFLAG = 0
AND WORKORDER.ISTASK = 0
AND WORKORDER.STATUS = 'COMP'
AND WORKORDER.STATUSDATE >= getdate() - 1
AND WORKORDER.LOCATION LIKE 'ABC%'
我想添加一个附加条件(可能在WHERE子句中),该附加条件将启用以下行为:
-如果工作单WORKTYPE为'PM',而WOPRIORITY为5,则不要包含它!
-如果工作单WORKTYPE是其他任何东西,则允许任何优先级
我不确定要在WHERE子句中放置哪种类型的IF或CASE语句来具体限制5 PM的优先级。任何帮助都将不胜感激!提前致谢!
我可能已经找到了解决方案!我在WHERE子句的末尾添加了以下行:
AND (case when WORKORDER.WORKTYPE='PM' then WORKORDER.WOPRIORITY<>5)
最佳答案
我认为您可能对此太在想...
WHERE NOT (WorkType = 'PM' AND WOPRIORITY = 5)