How can I Write a select statement based on the InvoiceTotal column of the Invoices table?

I have a homework problem where it asks me to

Write a select statement based on the InvoiceTotal column of the Invoices table

It wants me to take that column and run 3 different CAST functions on it andchange the data type. I know how to do that, but how do I select the column based on the table its in? Or is it basically saying to just select that table and include it in the result set along with the other columns I create using the cast function? But I think they don’t want the original InvoiceTotal Column included in the result set?

Task: Write a select statement based on the InvoiceTotal column of the Invoices table:
 Use the CAST function to return the first column as an integer
value. Name it IntTotal.
 Use the CAST function to return the second column as datatype decimal with one
digit to the right. Name it DecimalTotal.
 Use the CONVERT function to return the third column as a datatype
that outputs 2 digits to the right of the decimal point and all comma’s to the
left (i.e. 3, 106.34). Name it FormatTotal.
*/
USE AP

SELECT InvoiceTotal,
CAST(InvoiceTotal AS int) intTotal,
CAST(InvoiceTotal AS decimal(8,1)) DecimalTotal
FROM Invoices;

Does based mean order perhaps? Or are they asking you to filter by the InvoiceTotal somehow? It looks more like an order but it’s not clear…

that’s what it seems like to me too

and you had the first two of the three columns correct

SELECT CAST(InvoiceTotal AS INT) AS intTotal
     , CAST(InvoiceTotal AS DECIMAL(8,1)) AS DecimalTotal
     , CONVERT( ... ) AS FormatTotal
  FROM Invoices;

i might have given the CONVERT a shot, but the syntax varies from one database to another, and you forgot to mention which one you’re using

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.