Toggle Navigation
Home
SQL Fundamentals
Data Retrieval
Select
Select Statement
Top
Distinct
Aliases
Sorting
Operators
Set Operators
Arithmetic Operators
Comparison Operators
Logical Operators
Like Clause
Operator Precedence
Join
Join
Inner Join
Left Join
Right Join
Full Join
Cross Join
Grouping Datasets
ROLLUP & CUBE
Built-In Functions
Built-In Functions
Aggregate Functions
Date Functions
Conversion Functions
String Functions
Data Modification
Insert
Select Into
Update
Delete & Truncate
Merge
Transactions
CTE
SQL Fundamentals
Data Retrieval
Select
Select Statement
Top
Distinct
Alias
Sorting
Operators
Set Operators
Arithmetic Operators
Comparison Operators
Logical Operators
Like Clause
Operator Precedence
Join
Join
Inner Join
Left Join
Right Join
Full Join
Cross Join
Grouping Datasets
ROLLUP and CUBE
Built-In Functions
Aggregate Functions
Date Functions
Conversion Functions
String Functions
Data Modification:
Insert
Select Into
Update
Delete and Truncate
Merge
Transactions
CTE
Conversion Functions
These built-in functions are used to manipulate data formats.
CAST:
Explicitly converts an expression from one data type to another.
SYNTAX:
CAST ( expression AS [data type] )
EXAMPLE
Query:
SELECT
CAST
(
9.2
AS INTEGER
)
AS
[CAST]
Output :
CAST
9
CONVERT:
Similar to CAST, COVERT also explicitly converts an expression from one data type to another.
SYNTAX:
CONVERT ( data type , expression [, style] )
EXAMPLE 1:
Query:
SELECT
CONVERT
(
VARCHAR
(
30
),
GETDATE
())
AS
[Default Style]
Output :
Default Style
Nov 23 2024 8:29PM
EXAMPLE 2:
Query:
SELECT
CONVERT
(
VARCHAR
(
30
),
GETDATE
(),
1
)
AS
[Without Century]
Output :
Without Century
11/23/24
EXAMPLE 3:
Query:
SELECT
CONVERT
(
VARCHAR
(
30
),
GETDATE
(),
101
)
AS
[With Century]
Output :
With Century
11/23/2024