I have a stored procedure in MS SQL, that takes 2 parameteres, for example
CREATE PROCEDURE MyProcedure
@A INT,
@B INT
AS
BEGIN
SELECT ...
FROM ...
WHERE [A] = @A AND [B] = @B
END
My question is. if i have @B = 0 i want in the select row like this where [A]=@A,wthout the [B]=@B.. how can i achieve this with a minimum code? thanks alot
Try the following:
SELECT ...
FROM ...
WHERE [A] = @A AND
(@B = 0 OR [B] = @B)
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