all groups > sql server (alternate) > june 2005 >
You're in the

sql server (alternate)

group:

Query help - giving a date range given the start date, thanks!


Query help - giving a date range given the start date, thanks! rong.guo NO[at]SPAM gmail.com
6/27/2005 11:59:46 AM
sql server (alternate):
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 *
[quoted text, click to view]
Where open_date between '5/31/2005' and ('5/31/2005'+5)
Re: Query help - giving a date range given the start date, thanks! jim_geissman NO[at]SPAM countrywide.com
6/27/2005 12:29:27 PM
Select *
[quoted text, click to view]
Where open_date between '5/31/2005' and dateadd(day,5,'5/31/2005')
Re: Query help - giving a date range given the start date, thanks! rong.guo NO[at]SPAM gmail.com
6/27/2005 2:25:44 PM
Thanks, great help!

[quoted text, click to view]
AddThis Social Bookmark Button