久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

SQL Server ISNUMERIC() 澄清

SQL Server ISNUMERIC() Clarification(SQL Server ISNUMERIC() 澄清)
本文介紹了SQL Server ISNUMERIC() 澄清的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我有一個(gè)表 X,里面有一個(gè) accountNo 的列表.該字段(accoutNo) 是一個(gè)nvarchar(8).現(xiàn)在的問(wèn)題是有時(shí)我們也會(huì)在該字段中獲取字符,我想將其轉(zhuǎn)換為 bigint.

I have a table X with a list of accountNo's. This field(accoutNo) is a nvarchar(8). Now issue here is sometimes we get characters in this field as well and I want to convert it into bigint.

抱歉,我無(wú)法將其以表格形式放在這里.

Sorry I'am not able to put this in a table format here.

我可以檢查 accountNo 是否是數(shù)值:

I'am able to check if a accountNo is a numeric value or not:

select x.accountNo from x where ISNUMERIC(x.accountNo)=1

但是當(dāng)我嘗試僅在 accountNo 是數(shù)字時(shí)才轉(zhuǎn)換值時(shí),我仍然不能,我很困惑:

but when I try to only convert the values if an accountNo is numeric, I still can't, I'm confused:

select x.accountNo, convert(bigint,x.accountNo) from x where ISNUMERIC(x.accountNo)=1

我收到的具體錯(cuò)誤:

消息 8114,級(jí)別 16,狀態(tài) 5,第 1 行錯(cuò)誤轉(zhuǎn)換數(shù)據(jù)類型nvarchar 到 bigint.

Msg 8114, Level 16, State 5, Line 1 Error converting data type nvarchar to bigint.

示例數(shù)據(jù)

accountNo  A0001001  A0001002  A0001003  /0005856  !0005046  ~0005872     A.005698 A/005623 A./00578 ./214536

推薦答案

你應(yīng)該使用 CAST()TRY_CAST() 代替:

You should use CAST() or TRY_CAST() instead:

declare @test nvarchar(8) = '12345678'
select cast(@test as bigint) -- errors on failure
select try_cast(@test as bigint) -- returns null on failure

另外,重要的是要指出 ISNUMERIC() 并不完美.來(lái)自文檔:

Also, important to point out the ISNUMERIC() isn't perfect. From the docs:

ISNUMERIC 對(duì)某些不是數(shù)字的字符返回 1,例如加號(hào) (+)、減號(hào) (-) 和有效的貨幣符號(hào),例如美元符號(hào) ($).有關(guān)貨幣符號(hào)的完整列表,請(qǐng)參閱 money 和 smallmoney (Transact-SQL).

ISNUMERIC returns 1 for some characters that are not numbers, such as plus (+), minus (-), and valid currency symbols such as the dollar sign ($). For a complete list of currency symbols, see money and smallmoney (Transact-SQL).

出于這個(gè)原因,我認(rèn)為邏輯檢查在這里沒(méi)有價(jià)值.最好對(duì)所有值使用 TRY_CAST(),無(wú)論是否存在字符,并以可預(yù)測(cè)的方式處理空響應(yīng).

For this reason I don't think the logical check is of value here. Best to use TRY_CAST() on all values, regardless of the presence of characters and handle the null response in a predictable manner.

這篇關(guān)于SQL Server ISNUMERIC() 澄清的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開(kāi)發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 国产免费一区二区三区 | 一区二区三区视频在线 | 精品毛片 | 日本在线黄色 | 日韩欧美国产精品一区二区三区 | 午夜网| 久久国产综合 | 二区中文 | 成人免费在线观看 | 黄色国产视频 | 成人亚洲视频 | 欧美久久久久久久久 | 一区二区三区四区免费观看 | 亚洲一页 | 日本精品一区二区三区在线观看视频 | 久久久久久国产精品 | 狠狠干狠狠操 | 欧美一区二区三区,视频 | 亚洲高清在线观看 | 伊人看片 | 99久久日韩精品免费热麻豆美女 | 国产成人小视频 | 激情小视频 | 九九热精| 在线免费观看成人 | 日韩一区二区在线视频 | 亚洲第一区国产精品 | 国产精品99久久久久久大便 | 亚洲欧洲在线视频 | 成人午夜影院 | 久久久久久亚洲 | 天堂影院av | 美女视频网站久久 | 国产97在线视频 | 一区二区三区中文字幕 | 一级毛片视频在线 | 国产精品福利在线观看 | 夜夜操天天操 | 亚洲国产欧美在线人成 | 国产亚洲精品久久午夜玫瑰园 | 欧美日韩国产三级 |