Optional Date filter

Hi there! - I am using date filter for a SQL question, I want to make that date filter optional. I'm using the below code, it is erroring out saying - "Incorrect syntax near '='."

EXEC Demo_GetEmployees  @createddate = [[{{createddate}}]]

When I profile with SSMS Profiler, I get the following

EXEC Demo_GetEmployees  @createddate =

How do I put optional date filter ?

Hi @sgayathri
Have a look here: https://www.metabase.com/docs/latest/questions/native-editor/sql-parameters#optional-clauses

EXEC Demo_GetEmployees [[@createddate = {{createddate}}]]

Thanks! It works this way. I've another concern, can't this be applied to a date range filter. When I give both the date filters optional, I get the error: Incorrect syntax near ','.

EXEC Demo_GetEmployees  [[@startdate = {{startdate}}]], [[@enddate = {{enddate}}]]

SQL Profiler

EXEC Demo_GetEmployees  ,

@sgayathri Try searching the forum, you're not the first person asking about Optional Clauses.
Since you require the user to input both start and end dates, then just use a single clause.

EXEC Demo_GetEmployees  [[@startdate = {{startdate}}, @enddate = {{enddate}}]]
1 Like