tags:

views:

48

answers:

2

How do I select all rows except for ones that where I get an error calling CONVERT on one of the columns?

For example, I am doing this:

SELECT rowid 
FROM batchinfo 
WHERE CONVERT(DATE, reporttime, 101) between '2010-07-01' and '2010-07-31';

And I am getting errors for some of the values. I have two questions:

  1. How can I skip the rows that have errors?
  2. How can I get only the rows that have errors?
+6  A: 

You can use the ISDATE() function to test the values.

SELECT *
FROM MyTable
WHERE ISDATE(MyColumn) != 1
bobs
MAN do I feel dumb. I've been developing with SQL server for 10 years, and I never knew there was an IsDate() function. How is that possible? +1 to you and thank you. And thanks to the asker for asking this.
David Stratton
Msg 102, Level 15, State 1, Line 3Incorrect syntax near '<'.
I__
What SQL Server version?
bobs
@|__: See update, try again using ANSI "not equals": `!=`
OMG Ponies
OMG Ponies
yes aahahhhahahahahha
I__
Hmm @Ponies, does that mean I know how to work with bad data (I accept), or that I'm a horrible modeler (may be true, but I'm not admitting it here)
bobs
@bobs: I was hoping I was clear that I meant working with the *aftermath* of bad modeling. I think the familiarity is awesome, but I don't know if the experience is enough to actually improve modeling skills because the situations only show how **not** to do things -- not how they should be, sadly.
OMG Ponies
no change it back to <>
I__
A: 

I believe you can utilize the IGNORE statement for this, I may be wrong though.

cbattlegear
how? please show me
I__