@pSUPPLIER_ID NVARCHAR(500)
@pSUPPLIER_NAME NVARCHAR(500)
Based on the availability of value in above variable, I need to swich fileds in WHERE clause. In single instance only one above variable contains value.
WHERE SUPPLIER.NAME LIKE @pSUPPLIER_NAME
Or
WHERE SUPPLIER.ID = @pSUPPLIER_ID
I have done this in two separate SQLs with a 'IF'.
IF(ISNULL(@PSUPPLIER_ID, 0) <> 0)
SELECT * FROM SUPPLIER WHERE SUPPLIER.ID = @pSUPPLIER_ID
ELSE
SELECT * FROM SUPPLIER WHERE SUPPLIER.NAME LIKE @pSUPPLIER_NAME
I want to know whether is there a possibility to have this in a single SQL 2005. This is in a SP at a given time only one input variable is passed(based on what we need to search). Simple 'OR' won't work I guess