Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date query

Author  Topic 

winnitbaker
Starting Member

7 Posts

Posted - 2012-04-03 : 15:33:54
What I would like to do it quite hard to explain. But my database is a nurse training database and with the use of a combo box I would like to display the training data by when the training expires by. So the options of the combo box could be 1 week, 2 weeks, 2 months. So if I was to do query today for 1 week it should display all the of the data from now until next week by the expiry date column. Below is some of the example data -

1001 PIN 09/12/2011 09/12/2012 Q Sarah Jones 1001
1002 BloodTransfusion1 10/11/2011 10/11/2012 Q Sarah Jones 1001

pduffin
Yak Posting Veteran

68 Posts

Posted - 2012-04-03 : 20:35:38
You did not give me much to go on but I tried.
Fields labeled as [*...] are descriptive as you did not supply the field names.
This should give all training which begins before the end of the selected time period from today and terminates after today. Which should be all active trainings within the time frame.

select *
from Table
where [*TrainingStartDate] <= dateadd(dd, datediff(dd,0,getdate()), [*number of days from dropdown]) and
[*TrainingExpiryDate] >= dateadd(dd, datediff(dd,0,getdate()), 0)
order by [*TrainingExpiryDate]

Likes to run, hates the runs!
Go to Top of Page
   

- Advertisement -