create table test1 ( id int identity(1,1), orderid varchar(2), value int ) go alter trigger tr_test on test1 for insert as declare @a char(2) select @a=isnull(max(orderid),'A@') from test1 if @a!='ZZ' begin if right(@a,1)='Z' begin update test1 set orderid=char(ascii(left(@a,1))+1)+'A' where id=(select id from inserted) end else begin update test1 set orderid=(left(@a,1))+char(ascii(right(@a,1))+1) where id=(select id from inserted) end end else rollback tran godeclare @a int set @a=1 while @a<400 begin insert into test1(value) select 1 set @a=@a+1 endselect * from test1 truncate table test1
能否解决,先谢过了!
(
id int identity(1,1),
orderid varchar(2),
value int
)
go
alter trigger tr_test on test1
for insert
as
declare @a char(2)
select @a=isnull(max(orderid),'A@') from test1
if @a!='ZZ'
begin
if right(@a,1)='Z'
begin
update test1
set orderid=char(ascii(left(@a,1))+1)+'A'
where id=(select id from inserted)
end
else
begin
update test1
set orderid=(left(@a,1))+char(ascii(right(@a,1))+1)
where id=(select id from inserted)
end
end
else
rollback tran
godeclare @a int
set @a=1
while @a<400
begin
insert into test1(value) select 1
set @a=@a+1
endselect * from test1
truncate table test1