我试图根据用户在Japser iReport网络界面上选择的值为我的WHERE子句添加一行。
Select KeyId, Name, WorkOrder
FROM orderTbl oT
WHERE
------- ????????????????? --------------
If userSelectedValue = 'Load'
oT.workOrder = 'accepted'
End If
------- ????????????????? --------------
我尝试按照CASE示例,但是会创建一个包含结果的新列,但不知道如何使用新值来获取我想要的记录。
Select KeyId, Name, WorkOrder
case
when userSelectedValue = 'Load' and workOrder ='accepted' then 'useWorkOrder'
else 'noWorkOrder'
end as "dropDown",
dropDown KeyId Name WorkOrder
---------------- ----- ------------- --------------
useWorkOrder 45 John Doe accepted
useWorkOrder 78 Bill Kearns accepted
noWorkOrder 23 Sandy York null
My Final Goal:
Retrieve 2 records if user selects "Load" from a drop-down (userSelectedValue="Load")
- 45 John Doe
- 78 Bill Kearns
Retrieve 1 record if user selects "Retrieve" from a drop-down (userSelectedValue="Retrieve")
- 23 Sandy York
答案 0 :(得分:0)
您不必使用CASE。您可以使用复合条件:
SELECT KeyId, Name
FROM orderTbl
WHERE (userSelectedValue = 'Load' and workOrder = 'accepted' AND DropDown = 'useWorkOrder')
OR (DropDown = 'noWorkOrder');
答案 1 :(得分:0)
您可以做的最简单的修改是:
Select KeyId, Name
WHERE case
when userSelectedValue = 'Load' and workOrder ='accepted' then 'useWorkOrder'
else 'noWorkOrder'
end = 'useWorkOrder'
答案 2 :(得分:0)
<强>解决方案:强>
我使用了所有想法的组合来实现这一目标。特别感谢Joseph B + gubble。
<强> 问题: 强>
Select KeyId, Name, WorkOrder
FROM orderTbl oT
WHERE
If userSelectedValue = 'Load'
oT.workOrder = 'accepted'
End If
<强> 答案: 强>
Select KeyId, Name, WorkOrder
FROM orderTbl oT
WHERE
case
when (oT.KeyId = userSelectedValue AND oT.workOrder = 'accepted'
OR de.KeyId = userSelectedValue)
then 'useWorkOrder'
else 'noWorkOrder'
end = 'useWorkOrder'