IF dentro de la cláusula where - SQL

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

gracias

preguntado el 01 de febrero de 12 a las 04:02

1 Respuestas

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.

Respondido 01 Feb 12, 08:02

Thank you for the reply. Now only i got the way to do it. thanks again. - NilushiH

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.