sql server optional parameters: syntax for between clause
Posted
by Aseem Gautam
on Stack Overflow
See other posts from Stack Overflow
or by Aseem Gautam
Published on 2010-04-15T17:09:06Z
Indexed on
2010/04/15
17:13 UTC
Read the original article
Hit count: 374
sql-server
|tsql
@FromDate datetime = null
@ToDate datetime = null
SELECT * FROM TABLE
WHERE ....
AND [PI].Date BETWEEN @FromDate AND @ToDate
When any date is null, the records are not displayed. What is the correct syntax so that I can get all records if any of the dates are null.
I have thought of this:
@FromDate datetime = '01/01/1901',
@ToDate datetime = '12/31/9999'
Thanks.
© Stack Overflow or respective owner