SQL - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL Convert

SQL Convert

shape Description

SQL Convert statement changes over a definition with one datatype then onto the next datatype.

shape Conceptual figure

shape Syntax

The syntax for SQL Convert is as follows
CONVERT (type [(length)], expression[, style]) Type =>Converting the datatype. length =>Optional field, and the length of resulting datatype . expression =>The esteems that need to convert to different datatype. style =>Discretionary field, and the configuration in that we used to change over information.

Types of converting

shape Description

There are some style code for converting data in desired format.

Converting float to real

Value Explanation
O Maximum 6 integers(Default)
1 8 integers
2 16 integers

Converting money to character

Value Explanation
O Negative interval delimiter, 2 integers on the side of the decimal
1 Interval delimiter,2 integer to the side of the decimal)
2 Negative interval delimiter, 4 integer to the side of the decimal

shape Examples

The below examples describes the SQL Converts operations on int, float datetime and varchar: [c] sql>SELECT CONVERT(int,13.65) Output of the above query will 13( converted into int)[/c] [c] sql>SELECT CONVERT (float, 13) Output of the above query will 13.00( converted into float)[/c] [c] sql>SELECT CONVERT (datetime , '2014-05-21') Output of the above query will '2014-05-21 00:00:00' (converted into date)[/c] [c] sql>SELECT CONVERT(VARCHAR, '1234.66', 2);  Output of the above query will 1,234.6  (converted into varchar)[/c] In the above example, all the values assigned with int, float, datetime and varchar values will be converted into an appropriate values based on the functionality and operations.

Summary

shape Key Points

  • SQL CONVERT Operation - Changes an definition from one datatype to a different datatype.