update tb_lawcategory set num= 
    (select count(*) as count from tb_Lawyer_User where Goodat like' % '+@good+'  %') where AreaName=@good

解决方案 »

  1.   

    --try:
    CREATE PROCEDURE sp_NewGoodLawyer 
    as 
    begin DECLARE    cur CURSOR FOR select AreaName from tb_Lawcategory where ParentID <>0 DECLARE @good nvarchar OPEN cur 
    FETCH NEXT FROM cur INTO @good while @@fetch_status=0 
    BEGIN 
        update tb_lawcategory 
    set num=(select count(*) as count from tb_Lawyer_User where Goodat like '%'+@good+'%') 
    where AreaName=@good
    FETCH NEXT FROM cur INTO @good 
    END CLOSE cur 
    DEALLOCATE cur 
    end 
    GO
      

  2.   

    CREATE PROCEDURE sp_NewGoodLawyer 
    as 
    begin DECLARE    cur CURSOR FOR select AreaName from tb_Lawcategory where ParentID <>0 DECLARE @good nvarchar OPEN cur 
    FETCH NEXT FROM cur INTO @good while @@fetch_status=0 
    BEGIN 
        update tb_lawcategory set num= 
        (select count(*) as count from tb_Lawyer_User where Goodat like '%'+@good+'%') where AreaName=@good
        FETCH NEXT FROM cur INTO @good 
    END CLOSE cur 
    DEALLOCATE cur 
    end 
    GO 
      

  3.   

    --Maybe u can use the following statement, instead of your whole procedure.
    update tb_lawcategory
    set num=(select count(*) as count from tb_Lawyer_User where Goodat like '%'+tb_lawcategory.AreaName+'%') 
      

  4.   

    不必用游标CREATE PROCEDURE sp_NewGoodLawyer 
    as 
    begin     update tb_lawcategory set num= 
        (select count(*) as count from tb_Lawyer_User where Goodat like '%'+ a.AreaName +'%') 
        where ParentID <>0 
    end 
    GO 
      

  5.   

    DECLARE @good nvarchar --->DECLARE @good nvarchar(100)
      

  6.   

    更正一下:
    update tb_lawcategory
    set num=(select count(*) as count from tb_Lawyer_User where Goodat like '%'+tb_lawcategory.AreaName+'%')
    where ParentID <>0