Show a field considering 10% of another column using SQL Server


I would like you to help me with this query, I want the costs that are greater than 1000 to show me in another column increased to 10%.

At the moment I only have:

SELECT * FROM tarifa

The result is the following:

I hope you can help me.

asked by Paul Julio 22.03.2017 в 23:00

2 answers


I suppose that when you say that the costs are greater than 1000 you mean that the price + tax is greater than 1000. The following code shows you the total price plus 10% of its value of the results whose prices + rates are greater than 1000 and shows them in a table called "Price_Total"

SELECT (1.10*precio) AS "Precio_Total" FROM tarifas where (precio + impuesto)> 1000

If the cost is simply the price without adding the tax the code would be the following:

SELECT (1.10*precio) AS "Precio_Total" FROM tarifas where precio > 1000

You do not need to use Transact SQL (use of if / else , for example) to display the results.

answered by 22.03.2017 в 23:23

If when you refer to cost you refer to the price column, the solution is the following query:

SELECT idtarifa
        WHEN precio > 1000
            THEN precio * 1.1
        ELSE precio
        END preciomasel10
FROM tarifa

answered by 23.03.2017 в 00:59