我在存储过程里加上事务处理
SET XACT_ABORT OFF 
BEGIN TRAN 
...
COMMIT TRAN 
仍然会报错

解决方案 »

  1.   

    SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GOALTER    proc updateKeywordResults
    asselect top 10000 keyword,category_id,count(keyword)as count into #dl_keyword_day from dl_keyword_day group by keyword,category_id order by count(keyword) desc
    update dl_keyword   set search_count = search_count+ kd.count,search_count_day=kd.count from  
    (select keyword,category_id,count from #dl_keyword_day) kd
    where kd.keyword=dl_keyword.keyword and kd.category_id=dl_keyword.category_iddelete from #dl_keyword_day where keyword in(select keyword from dl_keyword)insert into dl_keyword (keyword,category_id,search_count,search_count_day)
    select keyword,category_id,count,count from #dl_keyword_day
    drop table #dl_keyword_day
    create table #dl_keyword_results 

    keyword varchar(100), 
    category_id int,
    results varchar(7000)
    )
    declare keyword_cursor cursor for select k_id from dl_keyword
    open keyword_cursor
    declare @k_id int
    fetch next from keyword_cursor into @k_id
    while @@FETCH_STATUS=0
    begin
    declare @keyword nvarchar(100)
    declare @category_id int
    select @keyword=keyword,@category_id=category_id from dl_keyword where k_id=@k_id
    declare @results varchar(8000)
    set @results=''
    if @category_id=1
    begin
    select @results=isnull(@results+',','')+ltrim(main_id) from dl_soft where title like'%'+@keyword+'%'
    end
    else if @category_id=2
    begin
    select @results=isnull(@results+',','')+ltrim(main_id) from dl_theme where title like'%'+@keyword+'%'
    end
    else if @category_id=3
    begin
    select @results=isnull(@results+',','')+ltrim(main_id) from dl_game where title like'%'+@keyword+'%'
    end
    if len(@results)>1
    begin
    set @results=right(@results,len(@results)-1)
    end
    insert into #dl_keyword_results values(@keyword,@category_id,@results)
    fetch next from keyword_cursor into @k_id
    end
    close keyword_cursor
    deallocate keyword_cursor
    delete from dl_keyword_day
    delete from dl_keyword_results
    insert into dl_keyword_results select * from #dl_keyword_results
    drop table #dl_keyword_results
    GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GOSQL里面有没有end 这样的方法,步骤多了确实是不好调试