views:

76

answers:

3

I've got a simple nvarchar(25) column in an SQL database table. Most of the time, this field should contain alphanumeric text. However, due to operator error, there are many instances where it contains only a number. Can I do a simple search in SQL to identify these cases? That is, determine which rows in the table contain only digits in this column. As an extension, could I also search for those column values which contain only digits and a space and/or slash.

In other languages (eg. Perl, Java) a regular expression would resolve this quickly and easily. But I haven't been able to find the equivalent in SQL.

+1  A: 

yes you can achive this by using isnumeric function available in sql sever

check more at this link : http://msdn.microsoft.com/en-us/library/aa933213(SQL.80).aspx

Pranay Rana
Cool. What if I want to search for "30/23" for example?
dave
In SQL 2000; thats going to be hard. In 2005 and up I would say use Regex.
u07ch
A: 
select column_name from table_name where IsNumeric(column_name) <> 1
sblom
+3  A: 

Numeric Only:

 SELECT * FROM Table WHERE ISNUMERIC(Field) = 1

With Space:

 SELECT * FROM Table WHERE Field LIKE '% %'

With Slash:

 SELECT * FROM Table WHERE Field LIKE '%/%'

Combined:

 SELECT * FROM Table WHERE ISNUMERIC(Field) = 1 OR  Field LIKE '% %' OR Field LIKE '%/%'
Jojo Sardez