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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -