Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query using coalesce
Message
De
10/03/2009 18:02:16
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01386988
Message ID:
01386999
Vues:
22
>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
>
It is not clear what you wanrt to do. Not sure if that might be:
Select distinct prtNum,
(Select coalesce(min(curqty),0)
from lens_invsum lens 
where lens.prtNum = lens_invsum.prtNum and invsts = 'R' and sitnam ='NJ')  as NJUsable
(Select coalesce(min(curqty),0)
from lens_invsum lens 
where lens.prtNum = lens_invsum.prtNum and invsts = 'R' and sitnam ='NV')  as NVUsable
from Lens_invsum
Order by prtnum
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform