Question

I can't post the whole procedure here because it would be to confusing. What I am trying to do is calculating VAT. To do that I need to multiply Share with 0,25.

 select.....
    (SALES_PRICE * 0.8) as Revenue, 
    (SALES_PRICE * 0.8 * 1-u.discount) as Share,
    (SALES_PRICE * 0.8 * 1-u.discount) * 0.25 as VAT, 
    (SALES_PRICE * 0.8 * 1-u.discount) + (isa.SALES_PRICE * 0.8 * (1-u.discount) * (0.25)) as Total

Edit: Got some great help and ended up with correct calculations and formatting. Here is the result:

       CONVERT(DECIMAL(30, 2), ( sales_price * 0.8 )) 
       AS Revenue, 
       CONVERT(DECIMAL(30, 2), ( sales_price * 0.8 * 1 - u.discount )) 
       AS Share, 
       CONVERT(DECIMAL(30, 2), ( sales_price * 0.8 * 1 - u.discount ) * 0.25) 
       AS VAT, 
       CONVERT(DECIMAL(30, 2), ( sales_price * 0.8 * 1 - u.discount ) * 1.25) 
       AS Total
Était-ce utile?

La solution

You need to use . as decimal separator for 0.25:

(SALES_PRICE * 0.8 * (1-u.discount) * 0.25) as VAT

To get only 2 decimal places, you can do CONVERT(DECIMAL(30,2), yourvalue).

To get the total, just multiply by 1.25 (SALES_PRICE * 0.8 * (1-u.discount) * 1.25)

Autres conseils

Change

(SALES_PRICE * 0.8 * 1-u.discount * 0,25) as VAT

to

(SALES_PRICE * 0.8 * 1-u.discount * 0.25) as VAT

Also, you might want to make use of some brackets, let say something like

(SALES_PRICE * 0.8 * (1-u.discount) * 0.25) as VAT

Have a look at Operator Precedence (Transact-SQL)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top