Can I have a if statement inside a where clause as in the follwing.
SELECT DISTINCT *
FROM product p
INNER JOIN product_to_vendor pv
ON pv.product_id = p.product_id
WHERE pv.vendor_id = @vendorId AND p.site_id = @siteId AND
IF (@productStatus < 4)
BEGIN
p.[rank] = @productStatus
END
thanks
SELECT DISTINCT *
FROM product p
INNER JOIN product_to_vendor pv
ON pv.product_id = p.product_id
WHERE pv.vendor_id = @vendorId
AND p.site_id = @siteId
AND (@productStatus < 4 AND p.[rank] = @productStatus)
I not sure about your requirements, but here it is showing how if-else can be constructed from boolean logic. Just assume the if (condition) is just another statement for AND.
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