Home Common Problem How to use convert function?

How to use convert function?

Jul 03, 2020 pm 03:07 PM
convert

The CONVERT function is used to convert numbers from one measurement system to another. The syntax is "CONVERT(number, from_unit, to_unit)"; the three parameters represent in turn: the value to be converted in "from_units"; the unit of the value; the unit of the result.

How to use convert function?

The CONVERT function is a function that converts numbers from one measurement system to another.

Syntax: CONVERT(number, from_unit, to_unit)

Parameters:

Number needs to be converted in units of from_units numerical value.

From_unit is the unit of the numerical number.

To_unit is the unit of the result.

convert function is used to convert data types

Example:

SELECT CONVERT (VARCHAR(5),12345)
Copy after login

Return: String '12345'

Other usage

With When the three data types of datetime, smalldatetime or sql_variant are used together,

CONVERT and CAST provide similar functions: explicitly converting an expression of a certain data type to another data type.

Syntax

Use CAST:

CAST ( expression AS data_type )
Copy after login

Use CONVERT:

CONVERT (data_type[(length)], expression [, style])
Copy after login

Parameters

expression

is any valid Microsoft SQL Server™ expression. See Expressions for more information.

data_type

Data types provided by the target system, including bigint and Sql_variant. User-defined data types cannot be used. For more information about the available data types, see Data Types.

length

Optional parameter for nchar, nvarchar, char, varchar, binary, or varbinary data type.

style

A date format style, used to convert datetime or smalldatetime data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types); or a string format style, used to convert Convert float, real, money, or smallmoney data to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data type).

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of How to use convert function?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)