Skip to content

Instantly share code, notes, and snippets.

@alikrc
Created July 12, 2018 13:13
Show Gist options
  • Save alikrc/58fa92ab6f09c7d275462923324f8f37 to your computer and use it in GitHub Desktop.
Save alikrc/58fa92ab6f09c7d275462923324f8f37 to your computer and use it in GitHub Desktop.
If param is not null then add to where clause
declare
@id int--=123
select @id
select * from FOOTABLE t
where
(@id is null or t.ID = @id) --if param is null it doesnt add the condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment