DECLARE @ID int
declare @T table(ID int identity ,Col nvarchar(50))
insert into @T(Col)
values('X')
set @ID=@@IDENTITY
set @ID=SCOPE_IDENTITY()
select @ID
go
declare @T table(ID int identity ,Col nvarchar(50))
insert into @T(Col)
output inserted.ID
values('X')
------解决方案-------------------- declare @id int
declare @Str_Return varchar(7)
--insert into tableName(Col) values('X')
-- set @ID=@@IDENTITY
--如触发器中有其它的insert 含有自增列表的操作,用这个
--set @ID=SCOPE_IDENTITY()
--测试
set @id=23
--生成ES00309格式
set @Str_Return = convert(varchar(7),@ID)
set @Str_Return = 'ES'+substring('00000',1,(5-len(@Str_Return)))+@Str_Return
print @Str_Return