SQL Server float format conversion string varchar method

Source: Internet
Author: User

SELECT CONVERT (varchar), CAST (@testFloat as Decimal (38,2)))
SELECT STR (@testFloat, 38, 2)

Import from Excel to sql2000, there is a column "contact" has become a float type, I want to convert to nvarchar type, with the following statement

Select convert (nvarchar (+), convert (int, contact)) from employee
Go

Data overflow, no!

Select convert (nvarchar), CONVERT (Decimal (11,0), contact) from employee
Go

Data Conversion Success!

SELECT CONVERT (nvarchar), CAST (Contact as decimal (11,0)) from employee

Go

Data Conversion Success!

SELECT STR (Contact us, one, 0) from employee
Go

Data Conversion Success!

Summary, float---decimal----nvarchar

Convert

Cast

Str

About conversion of float in SQL Server to varchar a float type field, to be converted to varchar, but after the decimal point is automatically deleted ... After the search can be obtained by the following conversions:

SELECT Cast (CAST (field as DECIMAL (20,7)) as VARCHAR ()) from table to be checked
Or

SELECT CONVERT (VARCHAR), CONVERT (DECIMAL (20,7), field)) from the table to be looked up

SQL Server float format conversion string varchar method (GO)

Related Article

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.