帮我看看这个存储过程是什么问题,感觉逻辑有错误!
存储 SQL
USE [szht]
GO
/****** Object: StoredProcedure [dbo].[sp_insert_admin] Script Date: 2013/4/29 10:23:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_insert_admin]
@id int,
@name varchar(120),
@pwd varchar(130),
@toptime datetime,
@lasttime datetime,
@rtn int output
as
declare
@tmpname varchar(120),
@tmppwd varchar(130),
@tmptoptime datetime,
@tmplasttime datetime
if exists(select * from [Admin] where Id=@id)
begin
select @tmpname=Name,@tmppwd=Pwd,@tmptoptime=TopTime,@tmplasttime=LastTime from [Admin] where Id=@id
if((@tmpname=@name) and (@tmppwd=@pwd) and (@tmptoptime=@toptime) and (@tmplasttime=@lasttime))
begin
set @rtn=0
end
else
begin
update [Admin] set Name=@name,Pwd=@pwd,LastTime=@lasttime where Id=@id
set @rtn=2
end
end
else
if exists(select * from [Admin] where Name=@name)
begin
select @tmppwd=Pwd,@tmptoptime=TopTime,@tmplasttime=LastTime from [Admin] where Name=@name
if((@tmppwd=@pwd) and (@tmptoptime=@toptime) and (@tmplasttime=@lasttime))
begin
set @rtn=0
end
else
begin
update [Admin] set Pwd=@pwd where Name=@name
set @rtn=2
end
end
else
begin
insert into [Admin] values(@name,@pwd,@toptime,@lasttime)
set @rtn=1
end
--是不是这个意思?
ALTER PROCEDURE [dbo].[sp_insert_admin]
@id int,
@name varchar(120),
@pwd varchar(130),
@toptime datetime,
@lasttime datetime,
@rtn int output
as
if exists(select * from [Admin] where Id=@id and Name=@name and Pwd=@tmppwd and TopTime=@tmptoptime and LastTime=@tmplasttime)
set @rtn=0
else
begin
if(exists(select * from [Admin] where Id=@id))
update [Admin]
set Name=@name and Pwd=@tmppwd and TopTime=@tmptoptime and LastTime=@tmplasttime
where id=@id
set @rtn=2
else
begin
insert?into?[Admin]?values(@name,@pwd,@toptime,@lasttime)
set?@rtn=1
end
end