Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Selecting date range

Selecting date range

Scheduled Pinned Locked Moved Database
questiondatabasecsshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tthellebuyck
    wrote on last edited by
    #1

    I need some help with a stored procedure, I have a table in my database that I am writing records to, specifically a BeginningDate field and EndingDate field. I want to be able to run a stored procedure that selects records based on a range of dates. This range of dates begins with monday and ends the following sunday, it covers an entire week. When I run the stored proc the where clause goes something like this: select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and BeginningDate >= @BeginDate and EndingDate <= @EndDate I know that it will not return any records if there is a date that is less than the EndDate. My question is how can I adjust this so it selects the one record based on a BeginDate and EndDate parameters?

    C 1 Reply Last reply
    0
    • T tthellebuyck

      I need some help with a stored procedure, I have a table in my database that I am writing records to, specifically a BeginningDate field and EndingDate field. I want to be able to run a stored procedure that selects records based on a range of dates. This range of dates begins with monday and ends the following sunday, it covers an entire week. When I run the stored proc the where clause goes something like this: select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and BeginningDate >= @BeginDate and EndingDate <= @EndDate I know that it will not return any records if there is a date that is less than the EndDate. My question is how can I adjust this so it selects the one record based on a BeginDate and EndDate parameters?

      C Offline
      C Offline
      coolestCoder
      wrote on last edited by
      #2

      select UserID, BeginningDate, EndingDate, From tableName where UserID = @UserID and ((BeginningDate >= @BeginDate and EndingDate <= @EndDate) OR (BeginningDate >= @BeginDate) OR (EndingDate <= @EndDate)) Hope thats what you want ?


      "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


      coolestCoder

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups