sql server - Optional DateTime Parameter in SQL -


i have set sql stored procedure parameters optional in front end combination of these filters can have values or not have values. problem when come pass null date in. sql produces error if leave null, have managed reading around problem , found using following should resolve error:

set @sessionstarted = isnull(@sessionstarted, getdate()) 

which however, it's not returning records should returning because it's looking records current date , time.

the parameter defined such:

@sessionstarted datetime = null, 

and clause particular parameter is:

(@sessionstarted null or visitdate = @sessionstarted) 

is there anyway round issue when value can't specified?

you use different date in isnull , detect it. '1900-01-01' feels "known invalid" day use in place of null.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -