Home All Groups Group Topic Archive Search About

Select data that can't be converted.

Author
13 Jul 2006 1:08 PM
R1gg4
Hi all,

I have a table with a string column, most of the data in there is in a
format that can be converted into a datetime type.

How can i just retrieve the rows that cannot be converted?

ie..
            TestColumn
Row1 12/04/2004
Row2 03/09/2003
Row3 dd/mm/yyyy
Row4 string
Row5 09/07/1998

I want a select statement that only returns those rows where the column
cannot be converted to a date. hope this makes sense.

Thanks,
R.

Author
13 Jul 2006 1:19 PM
Tracy McKibben
R1gg4 wrote:
Show quote
> Hi all,
>
> I have a table with a string column, most of the data in there is in a
> format that can be converted into a datetime type.
>
> How can i just retrieve the rows that cannot be converted?
>
> ie..
>             TestColumn
> Row1 12/04/2004
> Row2 03/09/2003
> Row3 dd/mm/yyyy
> Row4 string
> Row5 09/07/1998
>
> I want a select statement that only returns those rows where the column
> cannot be converted to a date. hope this makes sense.
>
> Thanks,
> R.
>
>

This isn't perfect, but might get you what you need:

SELECT *
FROM table
WHERE ISDATE(TestColumn) = 0


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
13 Jul 2006 1:37 PM
R1gg4
Thanks for that,

Are there IS functions for all the data types?

Regards,
R.

Show quote
"Tracy McKibben" <tr***@realsqlguy.com> wrote in message
news:%23HtIA8npGHA.2292@TK2MSFTNGP05.phx.gbl...
> R1gg4 wrote:
>> Hi all,
>>
>> I have a table with a string column, most of the data in there is in a
>> format that can be converted into a datetime type.
>>
>> How can i just retrieve the rows that cannot be converted?
>>
>> ie..
>>             TestColumn
>> Row1 12/04/2004
>> Row2 03/09/2003
>> Row3 dd/mm/yyyy
>> Row4 string
>> Row5 09/07/1998
>>
>> I want a select statement that only returns those rows where the column
>> cannot be converted to a date. hope this makes sense.
>>
>> Thanks,
>> R.
>
> This isn't perfect, but might get you what you need:
>
> SELECT *
> FROM table
> WHERE ISDATE(TestColumn) = 0
>
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
Author
13 Jul 2006 1:44 PM
Tracy McKibben
R1gg4 wrote:
> Thanks for that,
>
> Are there IS functions for all the data types?
>

Not all of them, no.  Books Online will tell you which ones there are.


--
Tracy McKibben
MCDBA
http://www.realsqlguy.com
Author
13 Jul 2006 1:53 PM
R1gg4
Thanks,

R.

Show quote
"Tracy McKibben" <tr***@realsqlguy.com> wrote in message
news:uGTDxJopGHA.516@TK2MSFTNGP05.phx.gbl...
> R1gg4 wrote:
>> Thanks for that,
>>
>> Are there IS functions for all the data types?
>>
>
> Not all of them, no.  Books Online will tell you which ones there are.
>
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com
Author
13 Jul 2006 1:22 PM
Alejandro Mesa
Try using function IsDate and "like" operator.

select *
from  dbo.t1
where c1 IsDate(c1) = 0
go

-- if you want just those rows where the column has this format
select *
from  dbo.t1
where c1 not like '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]'
go


AMB


Show quote
"R1gg4" wrote:

> Hi all,
>
> I have a table with a string column, most of the data in there is in a
> format that can be converted into a datetime type.
>
> How can i just retrieve the rows that cannot be converted?
>
> ie..
>             TestColumn
> Row1 12/04/2004
> Row2 03/09/2003
> Row3 dd/mm/yyyy
> Row4 string
> Row5 09/07/1998
>
> I want a select statement that only returns those rows where the column
> cannot be converted to a date. hope this makes sense.
>
> Thanks,
> R.
>
>
>
Author
13 Jul 2006 1:28 PM
Alejandro Mesa
Correction,

select *
from  dbo.t1
where IsDate(c1) = 0
go


AMB

Show quote
"Alejandro Mesa" wrote:

> Try using function IsDate and "like" operator.
>
> select *
> from  dbo.t1
> where c1 IsDate(c1) = 0
> go
>
> -- if you want just those rows where the column has this format
> select *
> from  dbo.t1
> where c1 not like '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]'
> go
>
>
> AMB
>
>
> "R1gg4" wrote:
>
> > Hi all,
> >
> > I have a table with a string column, most of the data in there is in a
> > format that can be converted into a datetime type.
> >
> > How can i just retrieve the rows that cannot be converted?
> >
> > ie..
> >             TestColumn
> > Row1 12/04/2004
> > Row2 03/09/2003
> > Row3 dd/mm/yyyy
> > Row4 string
> > Row5 09/07/1998
> >
> > I want a select statement that only returns those rows where the column
> > cannot be converted to a date. hope this makes sense.
> >
> > Thanks,
> > R.
> >
> >
> >

AddThis Social Bookmark Button