create table employee( Employee_ID int primary key, Name nvarchar(20),
Gender nvarchar(2), DOJ datetime, Manager nvarchar(20),
Department nvarchar(20),
Tenure as (SELECT DATEDIFF(year, GETDATE(),DOJ ) ) )
错误:
在这种情况下不允许子查询。仅允许标量表达式。
答案 0 :(得分:4)
对于计算列,您不需要使用SELECT
语句:
create table employee (
Employee_ID int primary key, Name nvarchar(20),
Gender nvarchar(2), DOJ datetime, Manager nvarchar(20),
Department nvarchar(20)
Tenure as (datediff(year, getdate(), DOJ))
)