Computed Column cannot be Persisted

前端 未结 4 1321
自闭症患者
自闭症患者 2020-12-29 21:46

I have a custom function, and I am trying to created a persisted column using this function.

It is giving me following error.

Computed column

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 22:24

    Instead of calling the UDF, Set the computed column expression to

    Case When Len(EmployeeSSN) = 0 Then 
          SUBSTRING(EmployeeSSN, 1, 3) + '-' + 
          SUBSTRING(EmployeeSSN, 4, 2) + '-' + 
          SUBSTRING(EmployeeSSN, 6, 4)
        Else EmployeeSSN End
    

    In the Create Table script you can add a column:

    [NewColumnName]  As
       (Case When len([UpdateUserId])=(0) T
             Then (((substring([UpdateUserId],(1),(3))+'-')+
                     substring([UpdateUserId],(4),(2)))+'-')+
                     substring([UpdateUserId],(6),(4)) 
             Else [UpdateUserId] End) PERSISTED,
    

提交回复
热议问题