SQL Server – Where Clause Depending on Parameter

Imagine you want to give a user the possiblity to filter for information about which other persons in your company lives in the same city. However, instead of a explicit city name filter, you just provide him a checkbox aka Filter for Hometown. When you are now running an SQL query, you will think about adding a where clause, which depends whether or not the checkbox is selected. Now this can be quite tricky, when you do not know the syntax.

Below is an example for the AdventureWorks database.

 

 

Tags

Categories

Meta

Peter Merkert Written by:

Be First to Comment

Leave a Reply