Nullify ‘where’ clause in SQL Server

Consider a scenario, you want to save a value in parameter table ,but later you want to return all the values or you want to nullify the where clause.You don’t want to touch the actual package but only want to modify the parameter table

In below example if you give @AddDateTime as -1 it will return all the element , if you give a specific value it will filter based on that value only

Declare @AddDateTime Datetime
set @AddDateTime = ‘2018-04-06 23:00:21.983’
–set @AddDateTime = -1
select code from [dbo].[Parameters]
where (@AddDateTime = -1 or AddDateTime =@AddDateTime)

 

Leave a comment