Hallo,
Ik heb een query probleempje.
Het betreft een voorraad app waarbij de artikel eenheden stuk, doos en meter zijn.
Artikelen hebben ook een verpakkingsaantal.
Dus wanneer de eenheid stuk is moet voor de waarde deze berekening worden uitgevoerd:
prijs x verpakkingsaantal x aantal.
Wanneer de eenheid doos is wordt de berekening zo:
prijs x aantal.
In de originele query zat er een foutje waardoor er nooit per doos werd gerekend.
Ik moest dus de query aanpassen en heb dit alsvolgt gedaan:
IF (SELECT ProductSupplier.Unit FROM ProductSupplier) = 'doos' BEGIN
SELECT Product.ProductName AS Beschrijving, Product.type, Product.length AS Lengte,
Product.thermal AS Thermisch, ColorName AS Kleur,
Color.ColorCode AS Kleurcode, Product.VitraluxCode, Product.Min, Product.Max, SUM(ProductSupplier.Quantity) AS Aantal,
SUM(ISNULL(Product.Length, 1) * ProductSupplier.Quantity * ProductSupplier.Price) AS Waarde, "
Product.ProductID FROM Product INNER JOIN ProductSupplier ON Product.ProductID = ProductSupplier.ProductID
LEFT OUTER JOIN Color ON Product.ColorID = Color.ColorID GROUP BY Product.ProductName,
Product.Type, Product.Length, Product.Thermal, Product.Min, Product.Max, Color.ColorName, Color.ColorCode, Product.VitraluxCode, Product.ProductID END
ELSE BEGIN
SELECT Product.ProductName AS Beschrijving, Product.type, Product.length AS Lengte,
Product.thermal AS Thermisch, ColorName AS Kleur,
Color.ColorCode AS Kleurcode, Product.VitraluxCode, Product.Min, Product.Max, SUM(ProductSupplier.Quantity) AS Aantal,
SUM(ISNULL(Product.Length, 1) * ProductSupplier.PackageQuantity * ProductSupplier.Quantity * ProductSupplier.Price) AS Waarde,
Product.ProductID FROM Product INNER JOIN ProductSupplier ON Product.ProductID = ProductSupplier.ProductID
LEFT OUTER JOIN Color ON Product.ColorID = Color.ColorID GROUP BY Product.ProductName,
Product.Type, Product.Length, Product.Thermal, Product.Min, Product.Max, Color.ColorName, Color.ColorCode, Product.VitraluxCode, Product.ProductID END
Maar daar krijg ik deze fout bij: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Ik heb weinig ervaring met if - else query's dus hoop ik dat iemand mij hier kan helpen?
Ik heb een query probleempje.
Het betreft een voorraad app waarbij de artikel eenheden stuk, doos en meter zijn.
Artikelen hebben ook een verpakkingsaantal.
Dus wanneer de eenheid stuk is moet voor de waarde deze berekening worden uitgevoerd:
prijs x verpakkingsaantal x aantal.
Wanneer de eenheid doos is wordt de berekening zo:
prijs x aantal.
In de originele query zat er een foutje waardoor er nooit per doos werd gerekend.
Ik moest dus de query aanpassen en heb dit alsvolgt gedaan:
IF (SELECT ProductSupplier.Unit FROM ProductSupplier) = 'doos' BEGIN
SELECT Product.ProductName AS Beschrijving, Product.type, Product.length AS Lengte,
Product.thermal AS Thermisch, ColorName AS Kleur,
Color.ColorCode AS Kleurcode, Product.VitraluxCode, Product.Min, Product.Max, SUM(ProductSupplier.Quantity) AS Aantal,
SUM(ISNULL(Product.Length, 1) * ProductSupplier.Quantity * ProductSupplier.Price) AS Waarde, "
Product.ProductID FROM Product INNER JOIN ProductSupplier ON Product.ProductID = ProductSupplier.ProductID
LEFT OUTER JOIN Color ON Product.ColorID = Color.ColorID GROUP BY Product.ProductName,
Product.Type, Product.Length, Product.Thermal, Product.Min, Product.Max, Color.ColorName, Color.ColorCode, Product.VitraluxCode, Product.ProductID END
ELSE BEGIN
SELECT Product.ProductName AS Beschrijving, Product.type, Product.length AS Lengte,
Product.thermal AS Thermisch, ColorName AS Kleur,
Color.ColorCode AS Kleurcode, Product.VitraluxCode, Product.Min, Product.Max, SUM(ProductSupplier.Quantity) AS Aantal,
SUM(ISNULL(Product.Length, 1) * ProductSupplier.PackageQuantity * ProductSupplier.Quantity * ProductSupplier.Price) AS Waarde,
Product.ProductID FROM Product INNER JOIN ProductSupplier ON Product.ProductID = ProductSupplier.ProductID
LEFT OUTER JOIN Color ON Product.ColorID = Color.ColorID GROUP BY Product.ProductName,
Product.Type, Product.Length, Product.Thermal, Product.Min, Product.Max, Color.ColorName, Color.ColorCode, Product.VitraluxCode, Product.ProductID END
Maar daar krijg ik deze fout bij: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Ik heb weinig ervaring met if - else query's dus hoop ik dat iemand mij hier kan helpen?