The Cast() Function is used to change the data type of a column. We can use the cast() function for various purpose.

Syntax:

Cast(Original_Expression as Desired_DataType)



We can use this function for the following purpose:

1. To concatenate string
2.. Joining two columns
3. Performing Unions of Table
4. Performing mathematical operation on columns

Example: For example we have an employee Table

Cast

Now we execute the following query to use Cast() Function.

Select Name, WorkingHours = Cast(WorkingHours as char(2)) + 'hours working a day' 
From Employee

Result:

cast1 The Convert() Function is used to convert a date/time value in different different formats. Click here to learn more

admin (155 Posts)


One Response to Cast() Function in SQL Server

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.