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. search only date

search only date

Scheduled Pinned Locked Moved Database
algorithmstutorialquestion
8 Posts 6 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
    test 09
    wrote on last edited by
    #1

    select a.*, b.ConstructionCompletionDate_dt from projects a join schedule b on a.projectid=b.projectid where projectname like @projectname or country like @country or clientcompany like @clientcompany or ConstructionCompletionDate_dt like ('%(@ConstructionCompletionDate_dt)%')

    this is how im searching.. where ConstructionCompletionDate_dt isonly yyyy from datetime field.. if im using '% %' for example if i search 2010,, all fields with 012 in mm/dd/yyyy are displaying... i want only rows with year 2010 how can i do..

    L M 2 Replies Last reply
    0
    • T test 09

      select a.*, b.ConstructionCompletionDate_dt from projects a join schedule b on a.projectid=b.projectid where projectname like @projectname or country like @country or clientcompany like @clientcompany or ConstructionCompletionDate_dt like ('%(@ConstructionCompletionDate_dt)%')

      this is how im searching.. where ConstructionCompletionDate_dt isonly yyyy from datetime field.. if im using '% %' for example if i search 2010,, all fields with 012 in mm/dd/yyyy are displaying... i want only rows with year 2010 how can i do..

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      test-09 wrote:

      where ConstructionCompletionDate_dt isonly yyyy from datetime field

      A real DateTime field that you converted to a VARCHAR(4)? The LIKE operator is more suitable to search through text-fields. How about something like this;

      SELECT *
      FROM HumanResources.Employee
      WHERE YEAR([BirthDate]) = 1972

      I are Troll :suss:

      1 Reply Last reply
      0
      • T test 09

        select a.*, b.ConstructionCompletionDate_dt from projects a join schedule b on a.projectid=b.projectid where projectname like @projectname or country like @country or clientcompany like @clientcompany or ConstructionCompletionDate_dt like ('%(@ConstructionCompletionDate_dt)%')

        this is how im searching.. where ConstructionCompletionDate_dt isonly yyyy from datetime field.. if im using '% %' for example if i search 2010,, all fields with 012 in mm/dd/yyyy are displaying... i want only rows with year 2010 how can i do..

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Tell me you are storing your dates as datetime and not varchar. Try the datepart keyword, something like

        where datepart(yyyy,ConstructionDate) = 2010

        Never underestimate the power of human stupidity RAH

        T 1 Reply Last reply
        0
        • M Mycroft Holmes

          Tell me you are storing your dates as datetime and not varchar. Try the datepart keyword, something like

          where datepart(yyyy,ConstructionDate) = 2010

          Never underestimate the power of human stupidity RAH

          T Offline
          T Offline
          test 09
          wrote on last edited by
          #4

          im storing it as varchar as this is comfortable to my requirement..

          D P M 3 Replies Last reply
          0
          • T test 09

            im storing it as varchar as this is comfortable to my requirement..

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #5

            You should use the correct data type then. Why are you not using Date as the datatype? You will be doing some casts and converts in your application which is error prone.

            1 Reply Last reply
            0
            • T test 09

              im storing it as varchar as this is comfortable to my requirement..

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Get comfortable with doing it the right way. Now!

              1 Reply Last reply
              0
              • T test 09

                im storing it as varchar as this is comfortable to my requirement..

                M Offline
                M Offline
                Mycroft Holmes
                wrote on last edited by
                #7

                test-09 wrote:

                m storing it as varchar

                This is the most basic error in data design, I recommend that you change your data type from varchar to datetime NOW The longer you delay the more work it will take to change. You will change eventually or the project will die, the downstream cost of this mistake is extreme and must be fixed immediately.

                Never underestimate the power of human stupidity RAH

                L 1 Reply Last reply
                0
                • M Mycroft Holmes

                  test-09 wrote:

                  m storing it as varchar

                  This is the most basic error in data design, I recommend that you change your data type from varchar to datetime NOW The longer you delay the more work it will take to change. You will change eventually or the project will die, the downstream cost of this mistake is extreme and must be fixed immediately.

                  Never underestimate the power of human stupidity RAH

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  I second that. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Getting an article published on CodeProject should be easier and faster.


                  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