/*修改用户信息*/
CREATE  PROCEDURE My_UpdateUserInfor
(
@name Nvarchar(20),
@status int,
@re varchar(100),
@logintime datetime,
@uploadnum int
)
AS
UPDATE  Users 
if @uploadnum is not null
begin
SET Users_uploadpicnum = Users_uploadpicnum + 1  end if @status is not null
         begin set... endWHERE Users_name=@name;RETURN
GO我的意思是为了防止更新部分字段,其他参数为空时会清空字段内容。所以想判断参数后再更新其字段。上面的写法不能通过语法检查,请问,改怎么样写来实现我的要求??

解决方案 »

  1.   

    UPDATE  Users 
    if @uploadnum is not null
    begin
    SET Users_uploadpicnum = Users_uploadpicnum + 1  end if @status is not null
             begin set... endWHERE Users_name=@name;?语法不正确
      

  2.   

    CREATE  PROCEDURE My_UpdateUserInfor
    (
    @name Nvarchar(20),
    @status int,
    @re varchar(100),
    @logintime datetime,
    @uploadnum int
    )
    AS
    if @uploadnum is not null
    update Users SET Users_uploadpicnum = Users_uploadpicnum + 1 
    where Users_name=@name
    if @status is not null
    update Users SET.................
    where Users_name=@name
    return
      

  3.   

    CREATE  PROCEDURE My_UpdateUserInfor
    (
    @name Nvarchar(20),
    @status int,
    @re varchar(100),
    @logintime datetime,
    @uploadnum int
    )
    AS
    begin
    update Users SET Users_uploadpicnum = Users_uploadpicnum + 1 
    where Users_name=@name and @uploadnum is not nullupdate Users SET.................
    where Users_name=@name and @status is not null--或加在条件里
    return
    end
      

  4.   

    谢谢楼上,
    我是想能不能先判断完字段,然后用一次update来更新(能只要实现吗)?
    如果像上面只要每判断一个参数,更新一下字段,这样是不是效率不高?