IsNumeric Function in MSSQL

Hi, before knowing about this Numeric function i was done lot of queries write for to know the column is numeric or alpha.
This sql function is return 1 if its integer, if not it return zero.

Determines whether an expression is a valid numeric type.
Syntax

ISNUMERIC ( expression )

Arguments
expression

example:

DECLARE @table table(tempcol nvarchar(10))

INSERT INTO @table VALUES(‘1’)
INSERT INTO @table VALUES(‘2’)
INSERT INTO @table VALUES(‘3’)
INSERT INTO @table VALUES(‘A’)
INSERT INTO @table VALUES(’72Zs’)

SELECT tempcol, ISNUMERIC(tempcol) from @table

Usage:
SELECT * FROM @table WHERE ISNUMERIC(tempcol) = 1
SELECT * FROM @table WHERE ISNUMERIC(tempcol) <> 1

Output

sdf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s