alter trigger insertt1 on t1 for insert as declare @maxnum char(4) select @maxnum=right('0000'+cast(max(cast(a as int))+1 as varchar(4)),4) from t1 update t1 set a=@maxnum from t1,inserted where t1.a=inserted.a go另外最好设置缺省值'0000'.
drop table test_01 go create table test_01 (id int identity(1,1), a int , c as convert(char(4),right((convert(char(10),id+1000000000)),4))) go insert test_01 values (234) select * from test_01
as
declare @maxnum char(4)
select @maxnum=right('0000'+cast(max(cast(a as int))+1 as varchar(4)),4) from t1
update t1 set a=@maxnum from t1,inserted where t1.a=inserted.a
go另外最好设置缺省值'0000'.
go
create table test_01 (id int identity(1,1), a int , c as convert(char(4),right((convert(char(10),id+1000000000)),4)))
go
insert test_01 values (234)
select * from test_01