views:

21

answers:

2

I have a 300.000 rows table; one of the columns is a varchar() but it really contains a date xx/xx/xxxx or x/x/xxxx or similar. But executing the following test yields an error:

SELECT CAST(MyDate as Datetime) FROM MyTable

The problem is that it doesn’t tell me in which row…

I have executed a series of “manual” updates by trial an error and performed simple updates to fix those, but there’s got to be some weird values that need to either be deleted or fixed.

For example I performed a simple test that fixed about 40 rows:

UPDATE MyTable SET MyDate = REPLACE(MyDate, '/000','/200') FROM MyTable WHERE MyDate like ('%/000%’)
UPDATE MyTable SET MyDate = REPLACE(MyDate, '/190','/199') FROM MyTable WHERE MyDate like ('%/190%’)

This fixed quite a few weird rows that had dates like 01/01/0003 and such. (Dates range from 1998 to 2010).

However, I’d like to know which rows are failing in the above select.

What would be the best way to print those so I can either delete them, edit them or see what to do? Thanks.

+1  A: 

Did you try the ISDATE function?

Jakob Christensen
I had forgotten about that, but it worked. Thanks.
Martín Marconcini
+1  A: 
SELECT
    *
FROM
   MyTable
WHERE
    ISDATE(MyDate) = 0
Robin Day
Thanks, that did it.
Martín Marconcini