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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Parameter choice SQL/Crystal Reports

Status
Not open for further replies.

sandeep2013

IS-IT--Management
Jun 26, 2013
4
US
I have two sets of date parameters in Crystal Reports each has a from and to. If they chose 1 date parameter they do not need to pick the other and vica versa or they can pick both

process date from/process date to
Claim Live Service Date From/Claim Live Service Date to.

Can i do this in the command in my SQL statment?
 
In this situation, I'd use a COALESCE on the dates in the query:
Code:
SELECT servicedate from My_Data_Table where servicedate between coalesce(@claimfrom,@claimto) and coalesce(@claimto,@claimfrom)

This requires servicedate to hold just a date, and not a time component. Where there is a time value to consider, I'd wrap a DATEADD around the upper extremity to take it to one second before midnight.

Code:
SELECT servicedate from My_Data_Table where servicedate between coalesce(@claimfrom,@claimto) and  DATEADD(ss,86399,coalesce(@claimto,@claimfrom))

(Should the @claimto be earlier than the @claimfrom, no results would be returned.)

soi là, soi carré
 
One of the things you could assume from the description is that the user can place a lower bound date only, and expect that the query will return records from that date on. (Likewise vice-versa for the upper bound.) So you'd have to code for a range of dates instead of just the submitted date.

-----------
With business clients like mine, you'd be better off herding cats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top