SQL Server中Money转Decimal
程序员文章站
2022-04-10 10:24:56
...
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 ServerDECLARE @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
下一篇: java思维导图
推荐阅读