Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    268

    Unanswered: datepart function

    Hi,

    I am using this function in a where clause to extract records for a certain year. For some reason, it returns all records. The query is complicated and using a lot of joins.

    Here is my where clause:

    DATEPART(yyyy,cm.CLM_Injury_Date) = 1947

    Any idea why?

  2. #2
    Join Date
    Mar 2007
    Location
    Holmestrand, Norway
    Posts
    332
    Could you please show the full query?
    Ole Kristian Velstadbråten Bangås - Virinco - MSSQL.no - Facebook - Twitter

  3. #3
    Join Date
    Aug 2011
    Posts
    5
    Is it a DATETIME field? If it's not, DATEPART will not always throw an error but, instead, has weird behavior.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The part of the WHERE clause that you've shown is fine. The problem is somewhere else.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •