Reputation: 29444
I have a table 'Products' that has these columns
ProductId
OriginalPrice
SalePrice
IsOnSale (bit)
Is it possible to create a view 'ProductsView' that has these columns
ProductId
Price
where price is either OriginalPrice or SalePrice depending on the value of IsOnSale?
Thanks in advance!
Upvotes: 0
Views: 119
Reputation: 3695
Yes, use a case statement:
Create view CurrentPrice AS
SELECT ProductId
, Price = CASE
WHEN IsOnSale = 1 THEN SalePrice
ELSE OriginalPrice
END
Upvotes: 4