Jag håller på med en "stored procedure" i SQL Server 2005 som ska hämta produkter i en given kategori.
Proceduren har en paramater som avgör om priset ska visas med eller utan moms. Momssatserna finns sparade i en tabell som heter "Tax" med fälten TaxID, TaxName och TaxValue där den sistnämda är procentsatsen.
Om parametern "@ShowTax" är 1 så ska momssatsen hämtas och läggas till på priserna, annars så ska priserna visas som de är. Antar att detta kan lösas med CASE men jag har inte lyckats klura ut hur. Vore tacksam om någon kunde leda mig i rätt riktning. :)
SQL-satsen i sin nuvarande form ser ut så här:
SELECT ROW_NUMBER() OVER (ORDER BY ProductItem.ProductID),
ProductGroup.ProductGroupID,
ProductDescription.ProductName,
ProductDescription.ProductShortDescription,
ProductPrice.ProductPrice,
ProductItem.ProductPriceRetail,
ProductItem.ProductPriceSale,
ProductImage.ImageUrlThumb,
Manufacturer.ManufacturerID,
Manufacturer.ManufacturerName
FROM ProductGroup INNER JOIN
ProductItem ON ProductGroup.ProductGroupID = ProductItem.ProductGroupID AND ProductItem.ProductDefault = 1 INNER JOIN
ProductCategoryLink ON ProductGroup.ProductGroupID = ProductCategoryLink.ProductGroupID LEFT JOIN
ProductPrice ON ProductItem.ProductPriceID = ProductPrice.ProductPriceID LEFT JOIN
ProductImage ON ProductItem.ProductID = ProductImage.ProductID AND ProductImage.ImageDefault = 1 LEFT JOIN
Manufacturer ON ProductGroup.ManufacturerID = Manufacturer.ManufacturerID LEFT JOIN
ProductDescription ON ProductItem.ProductID = ProductDescription.ProductID
WHERE ProductDescription.LanguageID = @LanguageID AND
ProductCategoryLink.CategoryID = @CategoryID