Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Review
So you think you can count?
Rounding functions and more
Review and practice

Instruction

Good!

The CAST() function allows us to convert values to another data type. However, it is not the only function that does this. In T-SQL, we also have the CONVERT() function. Here is an example:

SELECT
  CONVERT(NUMERIC, HP) / Level AS Ratio
FROM Character;

The difference is that this function needs two arguments: the first is the new data type, and the second is the value to convert. There are other differences as well, but they are for more advanced T-SQL usage, and we will not discuss them in this course.

CAST() complies with the ANSI standard, but CONVERT() is specific to SQL Server. For simple conversions, we recommend the ANSI standard.

Exercise

Each character has an AccountBalance stored as a decimal value. Show each character's Id and account balance. Display the account balance as an integer. Use CONVERT(). Name the column ConvertedBalance.