当前位置:Gxlcms > mysql > SQLServer中Money转Decimal

SQLServer中Money转Decimal

时间:2021-07-01 10:21:17 帮助过:263人阅读

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

人气教程排行