Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    55

    Unanswered: Error with SUBSTRING on a DATE column

    Hello,

    I tried to run this query and got an error.
    Schedat is a date field. Yrgiving is char. How do I compare the YYYY part of schedat to yrgiving?


    select schedat, yrgiving
    from tb950
    where substring(schedat,1,4) <> yrgiving;

    Msg 8116, Level 16, State 1, Line 1
    Argument data type smalldatetime is invalid for argument 1 of substring function.


    Thanks for any input.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    WHERE YEAR(schedat) <> CAST(yrgiving AS INTEGER)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Aug 2008
    Posts
    55
    Quote Originally Posted by r937
    WHERE YEAR(schedat) <> CAST(yrgiving AS INTEGER)
    Thank you so much R937 !

Posting Permissions

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