ALTER procedure Sp_StudentBaseInfo_Update_WhereString
--学生基本信息表参数
@sfzh char (20)=null , --身份证号
@xh char (15) = null , --学号
@xm char (24) = null , --姓名
@yx char (28) = null , --院校
@zy char (30) = null , --专业
         @xxbgsj DateTime=null,
--条件字段
@tj varchar(1000)=''


as
begin tran

--组合WHERE条件
    if @tj<>'' 
   set @tj= ' where '+  @tj
 
     --修改学生基本信息
declare @s nvarchar(4000)
set @s='
     UPDATE StudentBaseInfo
     SET sfzh = ISNULL(@sfzh, sfzh), xh = ISNULL(@xh, xh), xm = ISNULL(@xm, xm), 
           yx = ISNULL(@yx, yx), zy = ISNULL(@zy, zy), xxbgsj = ISNULL(@xxbgsj, xxbgsj) '
 + @tj  --总是报错
    exec sp_executesql @s
,N' @sfzh char (20),@xh char (15),@xm char (24)
,@yx char (28), @zy char (30),@xxbgsj DateTime'
,@sfzh,@xh,@xm,@yx,@zy,@xxbgsj

      if @@error <> 0
goto ErrorHandle
      
      commit tran
      return 0
      
      ErrorHandle: 
rollback tran
return -10005 --更新操作失败