Label:Original: http://www.2cto.com/database/201310/250880.html SQL cast and CONVERT usage detailed Summary: The following applies only to MySQL SELECT {fn CONCAT (CONVERT (User_id,char), user_name)} as Str from T_sys_user The following article applies only to sqlserver2008 SELECT {fn CONCAT (CONVERT (char,user_id), user_name)} as Str from T_sys_user The following SQL
GrammarUse CAST:
CAST (expression as data_type)
Use CONVERT:
CONVERT (data_type[(length)], expression [, style])
ParametersExpression
Is any valid Microsoft SQL Server expression. For more information, see expressions.
Data_type
The data types provided by the target system, including bigint and sql_variant. You cannot use user-defined data types. For more
SyntaxUse CAST:
CAST (expression AS data_type)
Use CONVERT:
CONVERT (data_type [(length)], expression [, style])
ParametersExpression
Is any valid Microsoft SQL Server "expression. For more information, see expressions.
Data_type
The data types provided by the target system, including bigint and SQL _variant. User-Defi
SQL Statement conversion Format function cast, convertBoth cast and convert are often used. Specially extracted as an article, convenient to find.Both cast and convert can perform data type conversions. In most cases, the two perform the same function, but the convert also provides some special date format conversions,
SQL Statement conversion Format function cast, convertBoth cast and convert are often used. Specially extracted as an article, convenient to find.Both cast and convert can perform data type conversions. In most cases, the two perform the same function, but the convert also provides some special date format conversions,
.exists Find out that the CategoryID in the category table are not equal to N.categoryid C.categoryid,c.[name] First query statement: Select C.categoryid,c.[name] from Category C left join News N in C.categoryid=n.categoryid where N.categoryid is Null Second query statement: Select Categoryid,[name] from category where NOT exists ( SELECT * FROM News where Category.categoryid=news.categoryid ) * The first performance is undoubtedly the best when the CategoryID is not repeated in the news table,
Both cast and convert in SQL Server convert an expression from one data type to another data type. Because SQL Server provides two features, it can be confusing to choose which feature should be chosen or in which case the feature should be used. Convert is designed for use with SQL Server, allowing for greater flexibi
scale are 9 and 2, respectively. The precision is the total number of digits, including the sum of the left and right digits of the decimal point. The number of decimal places is the right-hand digit. This means that the largest integer value that this example can support is 9999999, and the smallest decimal number is 0.01. SELECT CAST (' 12.5 ' as Decimal (9,2))The Decimal data type displays significant decimal digits in the result grid: 12.50the de
Label:Both cast and convert are often used. Specially extracted as an article, convenient to find. Both cast and convert can perform data type conversions. In most cases, the two perform the same function, but the convert also provides some special date format conversions, and cast does not have this function. Since convert includes all the functions of
Document directory
Data Type Conversion
Data Type Conversion
In Transact-SQL, there may be two levels of data type conversion:
When the data of one object is moved to another object, or the data between two objects is compared or combined, the data may have to be converted from the Data Type of one object to the Data Type of another object.
When you move data from a Transact-SQL result column, retur
Detailed description of the difference between cast and convert for forced type conversion in SQL SERVER, castconvert
Difference between cast and convert forced conversions in SQL SERVER
In SQL SERVER, cast and convert functions
1.sqlserver CAST and CONVERT functionsExplicitly converts an expression of a data type to another data type. CAST and CONVERT provide similar functionality.GrammarUsing CAST:CAST (expression as data_type)Using CONVERT:CONVERT (data_type[(length)], expression [, style])ParametersExpressionIs any valid Microsoft SQL Server expression. For more information, see expr
Tags: var SQL Server reference format alt man Read mailbox value 1 overview This article focuses on the two functions involved in type conversion in SQL Server: Cast and convert. 2 Specific content 2.1 CAST (1) Role: An expression that converts an expression of one data type to another data type. (2) Definition: 1
First, the CONVERT functionCharacter Set conversions: convert (XXX USING gb2312) type conversions are the same as SQL Server, but differ on type parameters: CAST (xxx as type), convert (XXX, type), type must be of the following type:Available type binary with binary prefix effect: binary character type, parameter: CHAR () Date: Date Time: Time datetime type: DATETIME float Points: DECIMAL integer: Signed un
-hand digit. This means that the largest integer value that this example can support is 9999999, and the smallest decimal number is 0.01.SELECT CAST (' 12.5 ' as Decimal (9,2))The Decimal data type displays significant decimal digits in the result grid: 12.50(5). The default values for precision and scale are 18 and 0, respectively. If these two values are not provided in the decimal type, SQL Server trunca
decimal type by using the cast () function, you first need to define the precision and scale of the decimal value. In this example, the precision and scale are 9 and 2, respectively. The precision is the total number of digits, including the sum of the left and right digits of the decimal point. The number of decimal places is the right-hand digit. This means that the largest integer value that this example can support is 9999999, and the smallest de
Explicitly converts a data type expression to another data type. CAST and CONVERT provide similar functions.Syntax
Use CAST:
CAST (expression AS data_type)
Use CONVERT:
CONVERT (data_type [(length)], expression [, style])Parameters
Expression
Is any valid Microsoft SQL Server expression.
Data_type
The data types provid
Reference: http://database.51cto.com/art/201005/201651.htmHttp://www.lai18.com/content/1693593.htmlDirectly on the example, the following is the processing of the field cost divided by 1000, leaving two decimal placesCast (SUM (a.costs)/1000 as Decimal (32,2))The cast () function is a conversion function, which is an expression that includes the source value and the target data type separated by the AS keyword.1) Convert the string ' 123 ' to int inte
Let's take a short time to introduce SQL rounding round functions
SQL Rounding 2007/11/01 16:35 question 1:
Will get 123 (will be omitted after the decimal point).
If you want to get two digits after the decimal point.
You need to change the above
SELECT CAST (' 123.456 ' as Decimal (2)) ===>123.46
It's automatically rounded!
These functions in fact, many online data, but in order to facilitate their own memory, I still decided to write a bit, all say good memory than bad writing, so or write a bit more.The cast () function essentially converts one type to another, such as converting a string type to a time type: SELECT CAST (' 2011-10-2 ' as datetime), or convert the numeric type to a string type: SELECT
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.