是否可以在sql server中的临时表中创建计算字段

时间:2013-02-25 15:51:52

标签: sql-server-2008 tsql

我的内联表值函数返回@table,暂时我正在考虑创建要计算的字段的可能性,并为其计算列规范添加公式。对我来说,在我的函数中减少sql语句的数量可能是一种更好的方法。

那么,它是否支持函数中的这种功能?

1 个答案:

答案 0 :(得分:3)

是的,你可以:

create function foo
(
    @seed int
)
returns @foo_t table
(
    [a] int not null,
    [b] int not null,
    [c] as ([a] + [b])
)
begin
    insert into @foo_t values (@seed, 2)
    insert into @foo_t values (@seed + 1, 3)

    return
end
go

select
    *
from foo(1)
go
相关问题