Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query - Between two dates

Status
Not open for further replies.

gooseriver

IS-IT--Management
Aug 4, 2006
93
CA
I have two date parameters DT1 and DT2. If I enter two dates - return data from within those two dates. If no values are entered in the parameters, return everything.

Not sure how to incorporate both.
 

something like this (untested, obviously)

select * from (
case when (your specific query) is null then (your select all query) else (your specific query) end
)


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Code:
SELECT (what ever)
FROM ???
WHERE @Dt1 IS NULL 
   OR SomeDate BETWEEN @Dt1 AND @Dt2


Borislav Borissov
VFP9 SP2, SQL Server
 
My two cents. If there are time values on the SomeDate column then you will have to account for those.
Maybe something like.
Code:
SELECT SomeDate >= @DT1 AND SomeDate < DATEADD(DAY, 1, @DT)
Where DT1 & DT2 have no time values.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top