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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. query for between dates

query for between dates

Scheduled Pinned Locked Moved Database
questiondatabasehelp
4 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.
  • I Offline
    I Offline
    icanmakeiteasy
    wrote on last edited by
    #1

    hi, i have a proble please help me i hav a table which consists of userid and date

    table1
    userid startdate enddate
    100 04/2/2009 04/30/2009

    user 100 is under work from 2nd april to 30th april if i try to give work from 04/10/2009 to 04/20/2009 to the user 100 now i should show that the user is already in work for given dates how can I?? thanks in advance...

    icanmakeiteasy

    W 1 Reply Last reply
    0
    • I icanmakeiteasy

      hi, i have a proble please help me i hav a table which consists of userid and date

      table1
      userid startdate enddate
      100 04/2/2009 04/30/2009

      user 100 is under work from 2nd april to 30th april if i try to give work from 04/10/2009 to 04/20/2009 to the user 100 now i should show that the user is already in work for given dates how can I?? thanks in advance...

      icanmakeiteasy

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      You can test the row and if the query returns a result they dates overlap. For example

      select ...
      from table1
      where (startdate between convert(datetime, '04/10/2009', 101) and convert('04/20/2009', 101)
      or enddate between convert(datetime, '04/10/2009', 101) and convert('04/20/2009', 101))
      and userid = 100

      However, use parameters instead of literals to define the start and end dates.

      The need to optimize rises from a bad design.My articles[^]

      I 1 Reply Last reply
      0
      • W Wendelius

        You can test the row and if the query returns a result they dates overlap. For example

        select ...
        from table1
        where (startdate between convert(datetime, '04/10/2009', 101) and convert('04/20/2009', 101)
        or enddate between convert(datetime, '04/10/2009', 101) and convert('04/20/2009', 101))
        and userid = 100

        However, use parameters instead of literals to define the start and end dates.

        The need to optimize rises from a bad design.My articles[^]

        I Offline
        I Offline
        icanmakeiteasy
        wrote on last edited by
        #3

        thx man thank you very much

        icanmakeiteasy

        W 1 Reply Last reply
        0
        • I icanmakeiteasy

          thx man thank you very much

          icanmakeiteasy

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome.

          The need to optimize rises from a bad design.My articles[^]

          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