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. DATE query

DATE query

Scheduled Pinned Locked Moved Database
databasequestion
6 Posts 4 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.
  • J Offline
    J Offline
    JGOnline
    wrote on last edited by
    #1

    I have a field called occdate which I need to query. This code works fine and retreives the record SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) However when i add a second parameter i get no results returned SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007) Can anyone tell me why?

    K C E 3 Replies Last reply
    0
    • J JGOnline

      I have a field called occdate which I need to query. This code works fine and retreives the record SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) However when i add a second parameter i get no results returned SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007) Can anyone tell me why?

      K Offline
      K Offline
      Keith Malwitz
      wrote on last edited by
      #2

      The where clause will be something along the lines of: WHERE OccDate BETWEEN StartDate AND EndDate But it is impossible to give you the exact syntax without knowing what database you are using.

      C 1 Reply Last reply
      0
      • K Keith Malwitz

        The where clause will be something along the lines of: WHERE OccDate BETWEEN StartDate AND EndDate But it is impossible to give you the exact syntax without knowing what database you are using.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Keith Malwitz wrote:

        The where clause will be something along the lines of

        Not necessarily. It is perfectly valid to say a is greater than x and a is less than y as the OP did. In fact, it gives more clarity because the BETWEEN clause doesn't intrinsically tell you if it is inclusive or exclusive of the values used. In the OP's case he's using a mix. The start date is inclusive and the end date is exclusive, so the BETWEEN clause is just not going to work for him. -- modified at 18:57 Sunday 27th August, 2006


        Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        1 Reply Last reply
        0
        • J JGOnline

          I have a field called occdate which I need to query. This code works fine and retreives the record SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) However when i add a second parameter i get no results returned SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007) Can anyone tell me why?

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Without knowing which database you are using this is difficult to answer. I always put the date in ISO format (i.e. yyyy-mm-dd) to ensure that the parser doesn't swap the month and date around depending on the locale. Also, I typically use parameters:

          SELECT OccID
          FROM dbo.People_Occ
          WHERE (OccDate >= @minDate) AND (OccDate < @maxDate)


          Upcoming Scottish Developers events: * UK Security Evangelists On Tour (2nd November, Edinburgh) * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          1 Reply Last reply
          0
          • J JGOnline

            I have a field called occdate which I need to query. This code works fine and retreives the record SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) However when i add a second parameter i get no results returned SELECT OccID FROM dbo.People_Occ WHERE (OccDate >= 01 / 08 / 2006) AND (OccDate < 01 / 08 / 2007) Can anyone tell me why?

            E Offline
            E Offline
            Eric Dahlvang
            wrote on last edited by
            #5

            Try this:

            SELECT OccID
            FROM dbo.People_Occ
            WHERE (OccDate >= '01/08/2006') AND (OccDate < '01/08/2007')

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            J 1 Reply Last reply
            0
            • E Eric Dahlvang

              Try this:

              SELECT OccID
              FROM dbo.People_Occ
              WHERE (OccDate >= '01/08/2006') AND (OccDate < '01/08/2007')

              --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

              J Offline
              J Offline
              JGOnline
              wrote on last edited by
              #6

              This worked. Thanks

              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