日期:2014-05-18 浏览次数:20608 次
CREATE proc [dbo].[spUpdClerkPwd] @ClerkId varchar(20), --被重置操作员号 @OPassWord varchar(20), --旧密码 @NPassWord varchar(20), --新密码 @OperateId varchar(20) --操作者员号(谁操作的) as begin set nocount on declare @field int declare @err int set @err=0 declare @rowClerk int declare @rowInfo int declare @rowRelation int select @rowClerk=COUNT(1) from Clerk where ClerkId = @ClerkId --select @rowClerk as rowClerk , @rowInfo as rowInfo, @rowRelation as rowRelation declare @Clerkrowcount int declare @oldClerk table( Id int, [ClerkId] [varchar](20) NULL, [PassWord] [varchar](20) NULL ) begin tran begin try --这段下面的看不懂,请解释下 update a set a.PassWord=(case when isnull(@OPassWord, '~NULL~')=ISNULL(@NPassWord, '~NULL~') then a.PassWord else @NPassWord end), UpdateDT=GETDATE() output deleted.Id,deleted.ClerkId,deleted.PassWord into @oldClerk from Clerk as a where a.ClerkId =@ClerkId and isnull(a.PassWord, '~NULL~')=isnull(@OPassWord, '~NULL~') and a.Flag=0 set @Clerkrowcount=@@ROWCOUNT --PRINT @ClerkRoleRelationrowcount if @Clerkrowcount=@rowClerk commit else begin rollback if @rowClerk=(select COUNT(1) from @oldClerk as a where a.ClerkId = @ClerkId ) set @err=50010 else set @err=50013 goto exit_bk end
--这段下面的看不懂,请解释下 --更新这个表a 设置Password字段等于@NPassWord 变量 --如果新密码和旧密码相等,更新PassWord等于PassWord,和更新1=1是一样,就是没变化 UPDATE a SET a.PassWord = ( CASE WHEN ISNULL(@OPassWord, '~NULL~') = ISNULL(@NPassWord, '~NULL~') THEN a.PassWord ELSE @NPassWord END ) , UpdateDT = GETDATE() --更新的同时用output子句输入被更新掉的结果进入到@oldClerk表变量 OUTPUT deleted.Id , deleted.ClerkId , deleted.PassWord INTO @oldClerk FROM Clerk AS a --这就是个where条件 WHERE a.ClerkId = @ClerkId AND ISNULL(a.PassWord, '~NULL~') = ISNULL(@OPassWord, '~NULL~') AND a.Flag = 0 SET @Clerkrowcount = @@ROWCOUNT
------解决方案--------------------