Convert Money from SQLServer to Decimal

Source: Internet
Author: User
In SQLServer, Money is converted to DecimalSQLServerDECLARE @ login, @ digitsSMALLINT, @ login, @ sqlstrNVARCHAR (100) DECLARE @ inputMONEYDECLARE @ fFLOATSET@input234214.4434SET @ int_digitsfloor (log10 (@ input )) + 1SET @ f @ input-fl

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

Convert Money to Decimal SQL Server in 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-floor(@input)SELECT @digits=case LEN(CAST(@f AS VARCHAR))-2WHEN -1 THEN 2WHEN 1 THEN 2WHEN 2 THEN 2WHEN 3 THEN 3ELSE 4ENDSET @total_digits=@int_digits+1+@digitsSET @sqlstr=N'SELECT CAST('+STR(@input,@total_digits,@total_digits)+' AS DECIMAL('+STR(@total_digits)+N','+STR(@digits)+N'))'exec sp_executesql @sqlstr

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.