Create Proc P_UpdateIP
@username varchar(20)
as
begin
   if exists (select 1 from CountIP where username=@username)
Begin
Update CountIP
set ipcount=T.CountIP
from
(select CountIP=count(A.ip)
 From TodayIp A,CountIP B where A.username=B.username and A.username=@username
)T
End
   Else
Begin
Insert into CountIP(username,ipcount)
select @username,count(A.ip) from TodayIp where username=@username
End
end

解决方案 »

  1.   

    Create Proc P_UpdateIP
    @username varchar(20)
    as
    begin
       if exists (select 1 from CountIP where username=@username)
    Begin
    Update CountIP
    set ipcount= ipcount + T.CountIP
    from
    (select CountIP=count(A.ip)
     From TodayIp A,CountIP B where A.username=B.username and A.username=@username
    )T
    End
       Else
    Begin
    Insert into CountIP(username,ipcount)
    select @username,count(ip) from TodayIp where username=@username
    End
    end
      

  2.   


    Create proc sp_textas   select  count(ip) as ipct,username into #temp from TodayIp group by username
       update  CountIP set ipcount=ipcount+ipCt from select A.* from #temp A leftjoin    CountIP B on A.username=B.username   insert into  CountIP (username ,ipcount ) 
       select  username,count(ip)  from  TodayIp B
       where not exists(select * from CountIP B where A.username=B.username)
       drop table #temp
    go
      

  3.   

    CREATE PROCEDURE IpCount  AS
    Select username,count(ip) ic into tempTable from todayIP group by username 
    update countIP set ipcount = ipcount + tempTable.ic from tempTable where countip.username = tempTable.username
    insert into countIP (username, ipcount) select * from tempTable where username not in (select username from countIP)
    drop table temptable
    delete from todayip
    GO
      

  4.   

    create proc p_total
    as
    select username, cnt=count(ip) into # from TodayIp group by username
    update a set ipcount=a.ipcount + b.cnt
    from CountIP a, # b
    where a.username = b.username
    insert CountIP select * from # a
    where not exists(
        select * from CountIP where username=a.username)
      

  5.   

    统计出相同的username的条数执行结果为A=======你执行的是什么语句?,你不要用语言描术怎样操作,直接说出你要达到什么目的.
      

  6.   

    Try:
    create proc T_proc
    as
    update CountIP set  ipcount=Today.ipcount
    from  
       CountIP,(select username,count(distinct ip) as ipcount  from TodayIp group by username) Today
    where 
       CountIP.username=Today.usernameinsert CountIP 
    select Today.* 
    from (select username,count(distinct ip) as ipcount  from TodayIp group by username) Today
    where  Today.username not in(select username from CountIP) 
      

  7.   

    create proc T_proc
    as
    update CountIP set  ipcount=ipcount+Today.ipcount
    from  
       CountIP,(select username,count(distinct ip) as ipcount  from TodayIp group by username) Today
    where 
       CountIP.username=Today.usernameinsert CountIP 
    select Today.* 
    from (select username,count(distinct ip) as ipcount  from TodayIp group by username) Today
    where  Today.username not in(select username from CountIP)