Code SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO createprocedure getPercent AS declare@CpyIDint declare Cpycursor cursorfor select fld_id from User_Crunode.T_CompanyInfo open Cpycursor fetchnextfrom Cpycursor into@CpyID while@@FETCH_STATUS=0 begin ----start declare@FirstCharvarchar(50) declare@FirstPointint declare@lenthint declare@Conditionnvarchar(1000) begin declare@AllCharvarchar(100) --set @AllChar='11,444,93,2,1' --set @CpyID=10 select@AllChar=fld_KeyWords from T_SpiderSettings where fld_CpyID=@CpyIDand fld_Remark like'%评%' set@lenth=len(@AllChar) createtable #Temp_String (FID intidentity, Content varchar(50)) set@FirstPoint=charindex( ',',@AllChar) while( @FirstPoint>0) begin set@FirstChar=substring(@AllChar,0,@FirstPoint) insertinto #Temp_String(Content) values (@FirstChar) set@AllChar=substring(@AllChar,@FirstPoint+1,@lenth) set@FirstPoint=charindex( ',',@AllChar) end insertinto #Temp_String(Content) values (@AllChar) declare mycursor cursorfor select Content from #Temp_String declare@valuevarchar(50) open mycursor fetchnextfrom mycursor into@value while@@FETCH_STATUS=0 begin iflen(@Condition)<=0or@Conditionisnull begin set@Condition='fld_keywordsFound like '''+@value+'''' end else begin set@Condition=@Condition+' or fld_keywordsFound like '''+@value+'''' end fetchnextfrom mycursor into@value end end declare@ConditionTotalnvarchar(1000) set@ConditionTotal='select @p=count(*) from T_spiderReports where (datepart(month,getdate()))=datepart(month,fld_datetime) and (datepart(day,getdate()))=datepart(day,fld_datetime) and (datepart(year,getdate()))=datepart(year,fld_datetime) and fld_cpyID= '+str(@CpyID) declare@CurrentNumTotalint execute sp_executeSql @ConditionTotal,N'@p int output',@CurrentNumTotal output if@CurrentNumTotalisnullorlen(@CurrentNumTotal)<=0 set@CurrentNumTotal=0 --print @CurrentNumTotal declare@ConditionTotalBadnvarchar(1000) set@ConditionTotalBad='select @p=count(*) from T_spiderReports where (datepart(month,getdate()))=datepart(month,fld_datetime) and (datepart(day,getdate()))=datepart(day,fld_datetime) and (datepart(year,getdate()))=datepart(year,fld_datetime) and fld_cpyID= '+str(@CpyID)+' and ('+@Condition+')' --print @ConditionTotalBad declare@CurrentNumTotalBadint execute sp_executeSql @ConditionTotalBad,N'@p int output',@CurrentNumTotalBad output if@CurrentNumTotalBadisnullorlen(@CurrentNumTotalBad)<=0 set@CurrentNumTotalBad=0 insertinto t_ResultTotal ([fld_Total],[fld_BadTotal],[fld_CpyID]) values (@CurrentNumTotal,@CurrentNumTotalBad,@CpyID) --print @CurrentNumTotalBad droptable #Temp_String close mycursor DEALLOCATE mycursor --end fetchnextfrom Cpycursor into@CpyID end close Cpycursor DEALLOCATE Cpycursor GO SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO
posted on
2009-08-14 11:43Robin99
阅读(133)
评论(0)
收藏举报