Results 1 to 3 of 3

Thread: Finding non valid dates with a char field

  1. #1
    Join Date
    Nov 2002
    Posts
    261

    Finding non valid dates with a char field

    I have a table with several million rows of data. There is a date field defined as a char(8) with some bad rows. i tried to locate them with below

    select date_stopped from patient_medication
    where isdate(convert(datetime,date_stopped)) = 1

    This won't work, I get the
    Server: Msg 242, Level 16, State 3, Line 1
    The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value

    Any way around this?

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    There are bad values, you may need check constraint on that column to ensure it gets good value.

  3. #3
    Join Date
    Dec 2004
    Posts
    502
    select date_stopped from patient_medication
    where isdate(date_stopped) = 0

Posting Permissions

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