I have a problem with my code :P obviously right?! Anyway...here's what it is...I want to have a STORED PROC that takes 3 args (@cat, @cutPrice, @option) and returns multiple results that have a type similar to @cat, and a price that is < or > @cutPrice depending on the @option keyword 'above' or 'below'. The problem is when I execute this...
EXEC spBookByPrice
@cat = 'business', @cutPrice = 0.00, @option = 'above'
...I get no results, but @option = ' ' shows all prices. Anyway here's my code....
ALTER PROC spBookByPrice
@cat varchar(12), @cutPrice money, @option varchar(5)
AS
BEGIN
SELECT
title AS 'Title:',
type AS 'Category:',
price AS 'Price:',
CASE
WHEN price >= @cutPrice THEN 'above'
WHEN price < @cutPrice THEN 'below'
--ELSE NULL
END AS 'Option:'
FROM dbo.titles
WHERE 'Option:' LIKE '%' + @option + '%'
GROUP BY type, title, price
HAVING type LIKE '%' + @cat + '%'
END
Is this what you need:
ALTER PROC spBookByPrice
@cat varchar(12), @cutPrice money, @option varchar(5)
AS
BEGIN
SELECT
title AS [Title:],
type AS [Category:],
price AS [Price:],
CASE
WHEN price >= @cutPrice THEN 'above'
WHEN price < @cutPrice THEN 'below'
--ELSE NULL
END AS [Option:]
FROM dbo.titles
WHERE (CASE WHEN price >= @cutPrice THEN 'above'
WHEN price < @cutPrice THEN 'below'
--ELSE NULL
END) LIKE '%' + @option + '%'
GROUP BY type, title, price
HAVING type LIKE '%' + @cat + '%'
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With