Friday, 17 May 2013

Cast() Function In Sql Server

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

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.


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

No comments:

Post a Comment