How to write a SQL query for user selected date range?

820 views Asked by At

I am trying to write a query that will capture calls completed within 24 hours and calls completed > 24 hours, by call rep, based off of user selected from date and to date range in a web form. I have a column for completion_date in the "yyyy-mm-dd 00:00:00" format, reps, type of call, call requested, and call assigned.

I really need some help!

1

There are 1 answers

2
Brett On BEST ANSWER

If you're trying to figure out the query, something like this should work:

SELECT reps, completion_date
FROM dbo
WHERE completion_date < DATEADD(DAY, DATEDIFF(DAY, 0, @DateSelectedByUser), -1)

This should get you the results within 24 hours, now for the results over 24 hours, you just use > rather than <