You are here: Re: Search Char in SQL query « MsSQL Server « IT news, forums, messages
Re: Search Char in SQL query

Posted by jaawaad on 10/26/02 11:52

Thanks for your reply.
Actually i was looking for something like ISNUMERIC. I just wanted to
pull out rows that contains only numbers and just eliminate the others
with chars in them.
Here is what i tried so far....

Select * from Mytable where ISNUMERIC(substring(COL2,2,10))

Assuming data field looks like this

COL2
A123X456
A45687E

I only want to do the check on portion of the string so i used
substring to take out the part i wanted to test against ISNUMERIC.

It shold work, but for some reason im getting an error msg. Any idea
what am i doing wrong here?

Thanks!

Tony Rogerson wrote:
> I looked at ISNUMERIC first but I don't think thats what you are after, but
> this will work...
>
> set nocount on
>
> declare @test table (
> MyData nvarchar(50) not null
> )
>
> insert @test values ( 'thisoneok' )
> insert @test values ( 'has123numbers' )
>
> declare @numbers table (
> digit char(1) not null
> )
> insert @numbers values( '0' )
> insert @numbers values( '1' )
> insert @numbers values( '2' )
> insert @numbers values( '3' )
> insert @numbers values( '4' )
> insert @numbers values( '5' )
> insert @numbers values( '6' )
> insert @numbers values( '7' )
> insert @numbers values( '8' )
> insert @numbers values( '9' )
>
> select *,
> has_numbers = case when exists (
> select *
> from @numbers n
> where len( replace( t.MyData, n.digit, '' ) ) <>
> len( t.MyData )
> ) then 'Y' else 'N' end
> from @test t
>
> --
> Tony Rogerson
> SQL Server MVP
> http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
> Server Consultant
> http://sqlserverfaq.com - free video tutorials
>
>
> <jaawaad@gmail.com> wrote in message
> news:1152546853.551581.273620@m73g2000cwd.googlegroups.com...
> >I have a text field in a table that contains number along with chars.
> > Is there a way i can write a query to show all the fields that contains
> > just Numbers or Char in a field??
> >
> > TBALE Example
> >
> > COL1 : COL2(nvarchar)
> > ---------------------------
> > 100 345G01
> > 200 123456789
> > 300 GQ9220
> >

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация