SQLTeam.com | Weblogs | Forums

SQL CAST Float

Hello all, I am attempting to write a query on a SQL learning site. I am getting an
error with the following query below (I tried many different iterations of this query, but only seem to make it fail worse). Thanks for any assistance/info.

SELECT
price,
amount,
CAST(price + amount AS FLOAT) as total FROM items;

The error indicates "total" column should be included within results
should be a Float value
Rows should have 3 rows
should return the expected results
Test Failed
the test results also indicate:
Test Results:
Results: Actual Results: Expected
price amount total
10 2 12
15 3 18
20 4 24

Post the EXACT text of the error message. The text you posted doesn't seem like a T-SQL error message - perhaps you are paraphrasing?

Usually you see errors when the data type of the columns you are trying to cast to float cannot be converted to float, or when the addition operation is invalid (e.g. if you are trying to add 2 strings etc.) It is impossible to say what the remedy is without the exact text of the error message.

It is the exact message, I am not paraphrasing. This is a SQL simulator for learning, I can post a link to the site if needed. I just wanted to know if the SQL syntax looks ok.
Thanks very much.

Maybe you should check the spelling of the columns or table name? I separated the Casting. Give that a try. I have not run it yet.

SELECT
  Price
, Amount
, CAST(ISNULL(Price, 0) AS FLOAT) + CAST(ISNULL(Amount, 0) AS FLOAT) AS [Total]
FROM Items

thanks for the update . I tried this query and got more errors. It is just a simulator, so I can't see how to resolve. I am going to move on with this issue as I was just looking to learn how to use CAST. Thanks for the help.