本文介紹了轉(zhuǎn)換為有效的十進制數(shù)據(jù)類型的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一列 [Cash] nvarchar(50)
包含稍后將在導入過程中轉(zhuǎn)換為 decimal(9,3)
的數(shù)據(jù),其中一些數(shù)據(jù)與看起來正常的數(shù)值一致,例如 134.630,-80.662 和 324.372. 有時我的數(shù)據(jù)帶有多個點,例如 1.324.372 和 -2.134.630.
有沒有辦法去掉這個多余的點.
I have a column [Cash] nvarchar(50)
that has data that will later be converted to decimal(9,3)
during an import process,some of the data is consistent with normal looking numeric values such as 134.630,-80.662 and 324.372. Occasionally I have data with multiple dots for the numeric values such as 1.324.372 and -2.134.630.
Is there a way of removing this extra dot.
推薦答案
declare @yourtable table(cash varchar(20))
insert @yourtable values('1.324.372')
insert @yourtable values('-2.134.630')
insert @yourtable values('1.234.567.89')
舊代碼:
select reverse(replace(replace(stuff(reverse(cash), charindex(
'.', reverse(cash)), 1, ','), '.', ''), ',', '.'))
from @yourtable
稍微升級的代碼(結(jié)果是一樣的):
Slightly upgraded code(result is the same):
select reverse(stuff(reverse(replace(cash, '.', '')),
charindex('.', reverse(cash)), 1, '.'))
from @yourtable
結(jié)果:
1324.372
-2134.630
1234567.89
這篇關于轉(zhuǎn)換為有效的十進制數(shù)據(jù)類型的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!