This document provides 3 exercises to practice using CAST and CONVERT functions to manipulate data types in SQL queries. The first exercise has users write a SELECT statement returning the ListPrice column in various data types. The second focuses on manipulating the DateAdded column's date and time components. And the third asks to format the OrderDate column in different date/time formats using CONVERT.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
31 views1 page
Chap 8 Data Types
This document provides 3 exercises to practice using CAST and CONVERT functions to manipulate data types in SQL queries. The first exercise has users write a SELECT statement returning the ListPrice column in various data types. The second focuses on manipulating the DateAdded column's date and time components. And the third asks to format the OrderDate column in different date/time formats using CONVERT.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Chapter 8
How to work with data types
Exercises 1. Write a SELECT statement that returns these columns from the Products table: The ListPrice column A column that uses the CAST function to return the ListPrice column with 1 digit to the right of the decimal point A column that uses the CONVERT function to return the ListPrice column as an integer A column that uses the CAST function to return the ListPrice column as an integer 2. Write a SELECT statement that returns these columns from the Products table: The DateAdded column A column that uses the CAST function to return the DateAdded column with its date only (year, month, and day) A column that uses the CAST function to return the DateAdded column with its full time only (hour, minutes, seconds, and milliseconds) A column that uses the CAST function to return the DateAdded column with just the month and day 3. Write a SELECT statement that returns these colums from the Orders table: A column that uses the CONVERT function to return the OrderDate column in this format: MM/DD/YYYY. In other words, use 2-digit months and days and a 4-digit year, and separate each date component with slashes. A column that uses the CONVERT function to return the OrderDate column with the date, and the hours and minutes on a 12-hour clock with an am/pm indicator. A column that uses the CONVERT function to return the OrderDate column with 2-digit hours, minutes, and seconds on a 24-hour clock. Use leading zeros for all date/time components.