我可以在where子句中使用if语句,如下所示。
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
感谢
答案 0 :(得分:1)
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)
我不确定您的要求,但这里显示了如何从布尔逻辑构造if-else
。只需假设if (condition)
只是AND
的另一个语句。