SQLUSA
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format
How to use the SQL isnumeric function?

Execute the following T-SQL script in Query Editor to demonstrate the application of the isnumeric() function to check for non-numeric zip (postal) codes like the ones used in Canada and United Kingdom:

USE AdventureWorks2008;

GO

SELECT DISTINCT

City,

StateProvinceCode,

Country = cr.Name,

PostalCode

FROM Person.Address a

INNER JOIN Person.StateProvince sp

ON a.StateProvinceID = sp.StateProvinceID

JOIN Person.CountryRegion cr

on cr.CountryRegionCode = sp.CountryRegionCode

WHERE ISNUMERIC(PostalCode)<> 1

ORDER BY Country, StateProvinceCode, City;

GO

------------

-- SQL ISALPHANUMERIC test

------------

-- SQL not alphanumeric string test - sql patindex pattern matching

SELECT DISTINCT LastName

FROM   AdventureWorks2008.Person.Person

WHERE  PATINDEX('%[^A-Za-z0-9]%',LastName) > 0

GO

/* Partial results

 

LastName

Ansman-Wolfe

Barreto de Mattos

Ben-Sachar

Costa Da Silva

De Matos Miranda Filho

*/

-- SQL ALPHANUMERIC test - isAlphaNumeric

SELECT DISTINCT LastName

FROM   AdventureWorks2008.Person.Person

WHERE  PATINDEX('%[^A-Za-z0-9]%',LastName)= 0

GO

/* Partial results

LastName

Abbas

Abel

Abercrombie

*/

------------

 

 

 

SQLUSA - The Best SQL Server 2008 Training in the World
 
 
SQLUSA.com Home Page