创建表格列,"作为常量值"

时间:2016-11-14 23:59:10

标签: sql-server

create table factura (   
    importe money,
    unidades_vendidas int,
    subtotal as (unidades_vendidas * importe),
    total  as (subtotal * 1.18)  -- (1.18 needs to be a constant value)
)

如何定义"总计"作为"小计"?

的1.18值

1 个答案:

答案 0 :(得分:2)

就像错误消息所说的那样,你不能有一个基于另一个计算列的计算列。在你的情况下,绕过它的方法是重做第二个字段中的计算。

create table factura (   
    importe money,
    unidades_vendidas int,
    subtotal as (unidades_vendidas * importe),
    total  as (unidades_vendidas * importe * 1.18) 
)

或者,您可以使用触发器为您填充