CAST function | SQL Tutorial and Query Example

Text copied!

CAST function


  • The syntax of the CAST function generally looks like this :
    Here's an example of how you might use the CAST function :

    1. Let's assume we have a table named "[Employees]".

    CAST(expression AS data_type)
    Remember :

    Using this function in a select statement won't modify the [Employees] table directly, but it will only be reflected in the select statement's output.

    To enhance your understanding of 'SQL functions', be sure to check out our next tutorial.
    CAST function
    SELECT *, CAST(Joining_Date AS date) AS [Date]
    FROM [Employees];
            
    CAST function

    Frequently Asked Questions :

    The CAST function in SQL converts data from one data type to another.
    The main difference between CAST and CONVERT in SQL is that CAST is ANSI standard while CONVERT is specific to SQL Server.
    In SQL-92, the CAST function is used for type conversion.
    In SQL, the CAST function for decimals converts data to a decimal data type.