I have this query
select devlocview.ENTERPRISENAME
FROM AlarmDeviceView alrmDevView
INNER JOIN devicelocationview devLocView
ON devlocview.oid=alrmdevview.deviceoid
LEFT OUTER JOIN DEVICEGROUPVIEW devGrpView
ON devlocview.oid=devgrpview.deviceoid
LEFT OUTER JOIN RackCapacityView rackCapView
ON devlocview.RACKID=rackCapView.oid
WHERE
(
alrmdevview.createddate = ( select max(alview.createddate)
from alarmdeviceview alview
WHERE alview.alarmoid=alrmdevview.alarmoid)
or alrmdevview.createddate IS NULL
)
AND devlocview.ENTERPRISENAME='Enterprise1'
AND devlocview.buildingname in (
CASE
WHEN $p{building} IS not NULL THEN $p{building}
WHEN $p{building} IS NULL THEN (select buildingname from cdmr.devicelocationview)
END
)
Here this part "select buildingname from cdmr.devicelocationview" returns multiple rows due to which I am getting
exception as 01427. 00000 – “single-row subquery returns more than
one row”
As per the requirement I want to assign multiple building when $p{building} is null
A
CASEis a scalar expression, it must evaluate to a scalar value. You can’t use it to return a multi-row set.The most common idiom I’ve seen for varying the condition based on whether an input value is NULL would look like this for your example: