How to convert string varchar in SQL Server in float format

Source: Internet
Author: User
Tags contact form

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

Importing from Excel to sql2000, there is a list of "contacts" that have become float types, and I want to convert to nvarchar type, using 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 Successful!

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

Go

Data Conversion Successful!

SELECT STR (Contact form, 0) from employee
Go

Data Conversion Successful!

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

Convert

Cast

Str

about float conversion to varchar in SQL Server
A Float Type field, to convert to varchar, but after the decimal point is automatically deleted ... After the search can be obtained through the following conversion:

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

SELECT CONVERT (VARCHAR), convert (DECIMAL (20,7), field) from the table to be searched

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/

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.