Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query using coalesce
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01386988
Message ID:
01387008
Views:
35
>HI All,
>
>It is late and my brain is not functioning... The below listed query returns the following error message after adding lines of code that are currently commented out:
>
>Subquery returned more than 1 value. This is not permitted when the subquery follows
=, !=, <, <= , >, >=
or when the subquery is used as an expression.
>
>How can I modify this query to prevent this error?
>
>Thank you,
>Daniel
>
>
>Select Distinct prtnum, 
>Coalesce((Select curqty from lens_invsum Lens where lens.prtnum = Lens_invsum.prtnum and invsts = 'R' and sitnam ='NJ'), 0) as NJUsable,
>Coalesce((Select curqty from lens_invsum Lens where lens.prtnum = Lens_invsum.prtnum and invsts = 'R' and sitnam ='NV'), 0) as NVUsable,
>--Coalesce((Select curqty from lens_invsum Lens where lens.prtnum = Lens_invsum.prtnum and invsts <> 'R' and sitnam ='NJ'), 0) as NJNotUseable,
>--Coalesce((Select curqty from lens_invsum Lens where lens.prtnum = Lens_invsum.prtnum and invsts <> 'R' and sitnam ='NV'), 0) as NVNotUseable
>from Lens_invsum
>Order by prtnum
>
select distinct PrtNum, ISNULL(c1.CurQty,0) as NJUsable, ISNULL(c2.CurQty,0) as NVUsable from Lens_InvSum L ;
LEFT JOIN (Select PrtNum, curqty from lens_invsum Lens where lens.prtnum = Lens_invsum.prtnum and invsts = 'R' and sitnam ='NJ') c1 on
L.PrtNum = c1.PrtNum LEFT JOIN (...) C2

In other words, use derived tables instead.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform