Home Forums SQL Server 2005 T-SQL (SS2K5) Query to retrieve a column depending on variable value? RE: Query to retrieve a column depending on variable value?

  • SELECT pi.ProductId, pi.name, pi.familyName,

    CASE pp.priceAssigned

    WHEN 'listPrice' THEN pi.listPrice

    WHEN 'price1' THEN pi.price1

    WHEN 'price2' THEN pi.price2

    WHEN 'price3' THEN pi.price3

    WHEN 'price4' THEN pi.price4

    WHEN 'price5' THEN pi.price5

    END AS [priceAssigned]

    FROM Customer c

    JOIN ProductPricePerCustomer pp ON pp.CustomerId = c.CustomerId

    JOIN ProductInfo pi ON pi.familyName = pp.familyName

    Far away is close at hand in the images of elsewhere.
    Anon.