0
0
SQLquery~10 mins

CAST and CONVERT for type changes in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the column 'price' to integer using CAST.

SQL
SELECT CAST(price AS [1]) FROM products;
Drag options to blanks, or click blank then click option'
AFLOAT
BDATE
CVARCHAR
DINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR instead of INT causes the value to become text.
Using DATE or FLOAT changes the type incorrectly.
2fill in blank
medium

Complete the code to convert the string '2023-01-01' to a DATE using CONVERT.

SQL
SELECT CONVERT([1], '2023-01-01', 23);
Drag options to blanks, or click blank then click option'
ADATE
BVARCHAR
CINT
DFLOAT
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR keeps the value as text.
Using INT or FLOAT causes conversion errors.
3fill in blank
hard

Fix the error in the code to convert '123.45' to integer using CAST.

SQL
SELECT CAST('123.45' AS [1]);
Drag options to blanks, or click blank then click option'
AVARCHAR
BINT
CFLOAT
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using FLOAT keeps the decimal and does not convert to integer.
Using VARCHAR does not convert to a number.
4fill in blank
hard

Fill both blanks to convert the column 'birthdate' to VARCHAR with length 10 using CONVERT.

SQL
SELECT CONVERT([1]([2]), birthdate, 23) FROM users;
Drag options to blanks, or click blank then click option'
AVARCHAR
BINT
C10
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using INT as type causes errors.
Omitting length for VARCHAR causes syntax errors.
5fill in blank
hard

Fill all three blanks to cast the column 'amount' to FLOAT and then convert it to VARCHAR with length 8.

SQL
SELECT CONVERT([1]([2]), CAST(amount AS [3])) FROM sales;
Drag options to blanks, or click blank then click option'
AVARCHAR
B8
CFLOAT
DINT
Attempts:
3 left
💡 Hint
Common Mistakes
Using INT instead of FLOAT loses decimals.
Omitting length for VARCHAR causes errors.