哪天有人写了一个
没有实现对帖子数目的修改,删除了目标用户的所有记录
alter proc CA_Forums_User_Unite
 @UserName1 varchar(100),
 @UserName2 varchar(100),
 @UserName3 varchar(100),
 @UserName4 varchar(100)
as
begin
 declare @sum int
 select @sum = sum(c.TotalPosts)
 from statistics_User c, User_Info g
 where c.UserID = g.UserID and g.UserName in(@UserName1, @UserName2, @UserName3) update statistics_User
 set TotalPosts = c.TotalPosts + @sum
 from statistics_User c, User_Info g
 where c.UserID = g.UserID and g.UserName = @UserName4 delete statistics_User from statistics_User c, User_Info g
 where c.UserID = g.UserID and g.UserName in(@UserName1, @UserName2, @UserName3) delete from User_Info where UserName in(@UserName1, @UserName2, @UserName3)
endGO

解决方案 »

  1.   

    create proc pr_合并用户
    @txtbox4 varchar(50),
    @txtbox1 varchar(50),
    @txtbox2 varchar(50)=null,
    @txtbox3 varchar(50)=null
    as
    set nocount ondeclare @UserID4 int
    select @UserID4=UserID from User_Info where UserName=@txtbox4
    --检查目标用户
    if @UserID4 is null 
       return 1                               --目标用户不存在declare @UserID1 int
    select @UserID1=UserID from User_Info where UserName=@txtbox1
    --检查源用户1
    if @UserID1 is null 
       return 2                               --源用户1不存在if @UserID1<>@UserID4           --不相等才修改
    begin
       update a set TotalPosts=a.TotalPosts+b.TotalPosts
       from statistics_User a,statistics_User b
       where a.UserID=@UserID4 and b.UserID=@UserID1   delete statistics_User where UserID=@UserID1   delete User_Info where UserID=@UserID1
    end--第二个用户
    set @UserID1=null
    select @UserID1=UserID from User_Info where UserName=@txtbox2if @UserID1 is not null and @UserID1<>@UserID4           --不相等才修改
    begin
       update a set TotalPosts=a.TotalPosts+b.TotalPosts
       from statistics_User a,statistics_User b
       where a.UserID=@UserID4 and b.UserID=@UserID1   delete statistics_User where UserID=@UserID1   delete User_Info where UserID=@UserID1
    end--第三个用户
    set @UserID1=null
    select @UserID1=UserID from User_Info where UserName=@txtbox3if @UserID1 is not null and @UserID1<>@UserID4           --不相等才修改
    begin
       update a set TotalPosts=a.TotalPosts+b.TotalPosts
       from statistics_User a,statistics_User b
       where a.UserID=@UserID4 and b.UserID=@UserID1   delete statistics_User where UserID=@UserID1   delete User_Info where UserID=@UserID1
    endgo
      

  2.   

    go之前加
    return 0                 --正常返回
      

  3.   

    你没调用吧调用方法:exec pr_合并用户 '目标用户名','第一个','第二个','第三个'
      

  4.   

    还要在写的存贮过程里面调用?
    我在查询分析起里写存贮过程
    然后去ASP。NET写那些代码
    我真不是很懂这些 初学 请指教
      

  5.   

    上面的create proc ......
    一直到go
    是建立存储过程的,执行后只是在数据库建立了一个可以调用的存储过程pr_合并用户调用可以在查询分析器进行,用语句
    exec pr_合并用户 '目标用户名','第一个','第二个','第三个'
    其中的 '目标用户名','第一个','第二个','第三个'都需要你用实际的用户名来代替也可以在客户端程序调用,你用ASP。NET,可以去响应版问调用方法