首頁 >資料庫 >mysql教程 >SQL Server中Money转Decimal

SQL Server中Money转Decimal

WBOY
WBOY原創
2016-06-07 14:55:152402瀏覽

SQL Server中Money转Decimal SQL Server DECLARE @int_digits SMALLINT,@digits SMALLINT,@total_digits SMALLINT,@sqlstr NVARCHAR(100)DECLARE @input MONEYDECLARE @f FLOATSET @input=234214.4434SET @int_digits=floor(log10(@input))+1SET @f=@input-fl

SQL Server中Money转Decimal SQL Server
DECLARE @int_digits SMALLINT,@digits SMALLINT,@total_digits SMALLINT,@sqlstr NVARCHAR(100)
DECLARE @input MONEY
DECLARE @f FLOAT
SET @input=234214.4434
SET @int_digits=floor(log10(@input))+1
SET @f=@input-floor(@input)
SELECT @digits=case LEN(CAST(@f AS VARCHAR))-2
WHEN -1 THEN 2
WHEN 1 THEN 2
WHEN 2 THEN 2
WHEN 3 THEN 3
ELSE 4
END
SET @total_digits=@int_digits+1+@digits
SET @sqlstr=N'SELECT CAST('+STR(@input,@total_digits,@total_digits)+' AS DECIMAL('+STR(@total_digits)+N','+STR(@digits)+N'))'
exec sp_executesql @sqlstr
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn