I need to build a WHERE clause based on the parameter that is been passed into a stored procedure.
For example: if param1 value is 1 then do like condition,
@param1 like '%'+ product.Status + '%'
else I want to ignore the like condition and it would return all rows….
How would I do it in the WHERE clause? Thanks,
SO you need to alter the where clause depending on a parameter. Use sp_executesql: you can build the query as a string, so you can add the where clause if @param = 1: