I would like to make a select query, I have several parameters but depending on the value I add the parameter to the where clause. I do not want to use dynamic query. For example this is my stored declaration:
EXEC GETProducts @ProductID INT = -1, @ProductName NVARCHAR(100) = NULL, @ProductManufacturerID INT = -1
I want all the products manufactured by ManufacturerID = 3
EXEC GETProducts -1, NULL, 3
I would like a query like this, I know it does no work, I also tried with CASE, but not working.
SELECT * FROM Product
WHERE
IF(@ProductID > -1)
BEGIN
ProductID = @ProductID
END
AND
IF(@ProductName <> '')
BEGIN
ProductName = @ProductName
END
AND
IF(@ProductManufacturerID > -1)
BEGIN
ProductManufacturerID = @ProductManufacturerID
END
Thanks for your help!!!