Chapter 8 How to work with data types Exercises 1·Write a SELECT statement that
ID: 3602151 • Letter: C
Question
Chapter 8 How to work with data types Exercises 1·Write a SELECT statement that returns these columns from the Products table: The list _price column A column that uses the FORMAT function to return the list price column with 1 digit to the right of the decimal point A column that uses the CONVERT function toreturn the list price column as an integer A column that uses the CAST function to return the list _price column as an integer 2. Write a SELECT statement that returns these columns from the Products table The date added column A column that uses the CAST function to return the date_added column with its date only (year, month, and day) A column that uses the CAST function to return the date_added column with just the year and the month A column that uses the CAST function to return the date_added column with its full time only (hour, minutes, and seconds)Explanation / Answer
1) SELECT list_price,
FORMAT( list_price , '##.#') AS formatedValue,
CONVERT(int, list_price) AS convertedValue,
CAST(9.5 AS int) AS castValue
FROM Products
2) SELECT date_added,
CAST( date_added AS date) AS dateOnly,
CAST(date_added AS varchar(6)) AS YearMonth,
CAST(date_added AS time) AS TimeOnly
FROM Products