CREATE TABLE PaperTable
(
PaperID int IDENTITY (1,1) NOT NULL
, PageNumber varchar(100)
, PaperAlphaID AS Cast(Right(Year(getDate()),2) as varchar(2)) +'-'+ PageNumber
);
结果当我添加“ 001”和“ 002”作为我的论文编号时得到:
PaperID PageNumber PaperAlphaID
------- ---------- ------------
1 001 15-001
2 002 15-002
但是我想用PaperAlphaID显示全年
PaperID PageNumber PaperAlphaID
------- ---------- ------------
1 001 2015-001
2 002 2015-002
代替15-001和15-002
最佳答案
删除右键功能并更新varchar(4)
CREATE TABLE PaperTable
(
PaperID int IDENTITY (1,1) NOT NULL
, PageNumber varchar(100)
, PaperAlphaID AS Cast(Year(getDate())) as varchar(4)) +'-'+ PageNumber
);