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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rong.guo@gmail.com

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

    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 *[color=blue]
    >From a[/color]
    Where open_date between '5/31/2005' and ('5/31/2005'+5)

  • jim_geissman@countrywide.com

    #2
    Re: Query help - giving a date range given the start date, thanks!

    Select *[color=blue]
    >From #a[/color]
    Where open_date between '5/31/2005' and dateadd(day,5,' 5/31/2005')

    Comment

    • rong.guo@gmail.com

      #3
      Re: Query help - giving a date range given the start date, thanks!

      Thanks, great help!

      jim_geissman@co untrywide.com wrote:[color=blue]
      > Select *[color=green]
      > >From #a[/color]
      > Where open_date between '5/31/2005' and dateadd(day,5,' 5/31/2005')[/color]

      Comment

      Working...