確定表達(dá)式是否為一個(gè)有效的數(shù)字類型。
ISNUMERIC ( expression )
expression
要計(jì)算的表達(dá)式。
int
當(dāng)輸入表達(dá)式得數(shù)為一個(gè)有效的整數(shù)、浮點(diǎn)數(shù)、money 或 decimal 類型,那么 ISNUMERIC 返回 1;否則返回 0。返回值為 1 確保可以將 expression 轉(zhuǎn)換為上述數(shù)字類型中的一種。
下面的示例返回 1,這是因?yàn)?zip 列包含有效的數(shù)值。
USE pubs
SELECT ISNUMERIC(zip)
FROM authors
GO
下面的示例對(duì)于 titles 表中的所有書(shū)名都返回 0,這是因?yàn)闆](méi)有一個(gè)書(shū)名是有效的數(shù)值。
USE pubs
GO
-- Because the title column is all character data, expect a result of 0
-- for the ISNUMERIC function.
SELECT SUBSTRING(title, 1, 15) type, price, ISNUMERIC(title)
FROM titles
GO
下面是結(jié)果集:
type price
--------------- -------------------------- -----------
The Busy Execut 19.99 0
Cooking with Co 11.95 0
You Can Combat 2.99 0
Straight Talk A 19.99 0
Silicon Valley 19.99 0
The Gourmet Mic 2.99 0
The Psychology (null) 0
But Is It User 22.95 0
Secrets of Sili 20.00 0
Net Etiquette (null) 0
Computer Phobic 21.59 0
Is Anger the En 10.95 0
Life Without Fe 7.00 0
Prolonged Data 19.99 0
Emotional Secur 7.99 0
Onions, Leeks, 20.95 0
Fifty Years in 11.95 0
Sushi, Anyone? 14.99 0
(18 row(s) affected)
相關(guān)文章