Koleman Parsley
Koleman Parsley

Reputation: 38

Using the CAST or CONVERT clause multiple times on the same SQL line

I am new to SQL and i thank you for your patience

I have this code

SELECT
    ProductName,
    ListPrice,
    DiscountPercent,
    CAST(ListPrice as decimal)Cast(DiscountPercent as decimal)(1-DiscountPercent/100.0)
FROM Products

I am needing the code to select the three columns, then in the fourth column to convert to decimal, and apply the discount to the listPrice and print it into the same column.

Forgive me if this has been answered I am still learning syntax and couldn't find what I was looking for.

I understand that there might be a simpler way and very open to hearing how to do it. I appreciate any input.

Thanks in advance!

Upvotes: 0

Views: 207

Answers (1)

sticky bit
sticky bit

Reputation: 37472

Sounds like you want a multiplication.

SELECT productname,
       listprice,
       discountpercent,
       cast(listprice AS decimal) * (1 - cast(discountpercent AS decimal) / 100.0)
       FROM products;

Though it is advisable to change the schema in a way that the columns already have the right data type.

Upvotes: 2

Related Questions