在SQL Server中将2个别名相乘

时间:2014-02-04 01:22:08

标签: sql-server alias multiplying

我有一个使用no FROM子句创建SELECT STATEMENT的赋值。 我正在尝试将Price和TaxRate相乘以生成TaxAmount列,但我收到错误,指出Price和TaxRate的列名无效。

SELECT '100 (dollars)' AS Price, '.07 (7 percent)' AS TaxRate,
Price * TaxRate AS TaxAmount, TaxAmount + Price AS Total

1 个答案:

答案 0 :(得分:1)

SELECT 100 AS Price, .07 AS TaxRate, (100 * .07) AS TaxAmount, ((100 * .07) + 100) AS Total

你不需要让它看起来像100(美元),我不认为,这是没有意义的。如果你真的这样做,你可以使用

SELECT '100 (dollars)' AS Price, '.07 (7 percent)' AS TaxRate, (100 * .07) AS TaxAmount, ((100 * .07) + 100) AS Total