Hi , Am trying to run this query (attached sample query) but I encounter an error. it says Msg 512, Level 16, State 1, Line 18
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. May i know what possible error with my script. any idea on how to fix this error. thanks.
select
case when a.SOURCE = 5 then (select case when supplier = 'POL' then supplier
when supplier <> 'POL' then supplier
else ' No Supplier' end
from #sample2 PB
where PB.esn = a.series AND PB.id = 'POL'
and PB.salesid = (select DISTINCT salesid from #sample3 WHERE cid = a.SOURCERECID
)
)
end AS SUPPLIER
from #sample a
where a.sourcedataareaid = 'POL'
and a.source=5
and dateadd(hour,8,a.createddatetime) >= @fromDateTime
and dateadd(hour,8,a.createddatetime) <= @toDateTime