|
Home > Archive > Microsoft SQL Server forum > June 2005 > Query help - giving a date range given the start date, thanks!
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Query help - giving a date range given the start date, thanks!
|
|
| rong.guo@gmail.com 2005-06-27, 8:23 pm |
| Hi Group!
I am struggling with a problem of giving a date range given the start
date.
Here is my example, I would need to get all the accounts opened between
each month end and the first 5 days of the next month. For example, in
the table created below, I would need accounts opened between
'5/31/2005' and '6/05/2005'. And my query is not working. Can anyone
help me out? Thanks a lot!
create table a
(person_id int
,account int
,open_date smalldatetime)
insert into a values(1,100001,'5/31/2005')
insert into a values(1,200001,'5/31/2005')
insert into a values(2,100002,'6/02/2005')
insert into a values(3,100003,'6/02/2005')
insert into a values(4,100004,'4/30/2004')
insert into a values(4,200002,'4/30/2004')
--my query--
Select *
>From a
Where open_date between '5/31/2005' and ('5/31/2005'+5)
| |
| jim_geissman@countrywide.com 2005-06-27, 8:23 pm |
| Select *
>From #a
Where open_date between '5/31/2005' and dateadd(day,5,'5/31/2005')
| |
| rong.guo@gmail.com 2005-06-27, 8:23 pm |
| Thanks, great help!
jim_geissman@country
wide.com wrote:
> Select *
> Where open_date between '5/31/2005' and dateadd(day,5,'5/31/2005')
|
|
|
|
|