我这ID 不是空啊 获取的是最好的那个啊 那还有什么办法获取ID 类, 我这个ID是标识列也是主键。 那这么获取我刚刚插入的那条数据的 ID
alter trigger userinfo on SchoolmateInfo for update as declare @ID int declare @max varchar(50) declare @ming varchar(50) if(@ID is not null) begin select @max=right(max(bianhao),5) from SchoolmateInfo update SchoolmateInfo set bianhao ='hnsxy132'+(@max+1) where id = (select @@identity) end
你的ID是自增列吗,如果是,用@@IDENTITY来获取.
从程序上看,如果你的 declare @ming varchar(50) if(@ID is not null) 这两句之间没有对@id赋值的话,那它肯定是NULL.
alter trigger userinfo on SchoolmateInfo for update as declare @ID int declare @max varchar(50) declare @count varchar(50) select @count=count(*) from SchoolmateInfo if(@count <= 1) begin update SchoolmateInfo set bianhao ='hnsxy13210001' where id = (select @@identity) end else begin select @max=right(max(bianhao),5) from SchoolmateInfo update SchoolmateInfo set bianhao ='hnsxy132'+(@max+1) where id = (select @@identity) end
id bianhao name birthday address contact calling1 hnsxy13201 yiyong 1987-05-19 湖南株洲 13522448572 1
2 NULL tangliu 1986-02-12 湖南长沙 13533435432 1
3 NULL juahg 1986-02-12 湖南长沙 13533435432 1
4 NULL juahg 1986-02-12 湖南长沙 13533435432 1
5 NULL ji 1986-02-12 湖南长沙 13533435432 1
6 NULL jishu 1986-02-12 湖南长沙 13533435432 1
那还有什么办法获取ID 类, 我这个ID是标识列也是主键。
那这么获取我刚刚插入的那条数据的 ID
as
declare @ID int
declare @max varchar(50)
declare @ming varchar(50) if(@ID is not null)
begin
select @max=right(max(bianhao),5) from SchoolmateInfo
update SchoolmateInfo set bianhao ='hnsxy132'+(@max+1) where id = (select @@identity)
end
你的ID是自增列吗,如果是,用@@IDENTITY来获取.
declare @ming varchar(50) if(@ID is not null)
这两句之间没有对@id赋值的话,那它肯定是NULL.
as
declare @ID int
declare @max varchar(50)
declare @count varchar(50)
select @count=count(*) from SchoolmateInfo
if(@count <= 1)
begin
update SchoolmateInfo set bianhao ='hnsxy13210001' where id = (select @@identity)
end
else
begin
select @max=right(max(bianhao),5) from SchoolmateInfo
update SchoolmateInfo set bianhao ='hnsxy132'+(@max+1) where id = (select @@identity)
end