首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么优化这些SQL语句的执行效率?紧

2012-02-29 
如何优化这些SQL语句的执行效率?紧急CREATEPROCEDURErecompair_tmASdeclare@startdatedatetimeselect@star

如何优化这些SQL语句的执行效率?紧急
CREATE   PROCEDURE   recompair_tm     AS
declare   @startdate   datetime

select   @startdate= '07-1-1 '

create   table   #radlog_allgroup(acname   varchar(50))
insert   into   #radlog_allgroup   select   distinct   accountname   from   radlog_group     where   logondatetime> =@startdate  

update   tm_upload_all   set   flag1=1   from   tm_upload_all,#radlog_allgroup   where   tm_upload_all.整理后的帐号=#radlog_allgroup.acname   and   tm_upload_all.开户日期> =@startdate
update   tm_upload_all   set   flag2=1,fgad2=#radlog_allgroup.acname   from   tm_upload_all,#radlog_allgroup   where   #radlog_allgroup.acname   like   tm_upload_all.整理后的帐号+ '% '   and   tm_upload_all.开户日期> =@startdate
update   tm_upload_all   set   flag3=1,fgad3=#radlog_allgroup.acname   from   tm_upload_all,#radlog_allgroup   where     tm_upload_all.开户日期> =@startdate   and   #radlog_allgroup.acname   like   '% '+   tm_upload_all.整理后的帐号
GO


[解决办法]
ALTER PROCEDURE recompair_tm AS
declare @startdate datetime

select @startdate= '07-1-1 '

create table #radlog_allgroup(acname varchar(50))
insert into #radlog_allgroup select distinct accountname from radlog_group where logondatetime> =@startdate

update tm_upload_all
set flag1=case when tm_upload_all.整理后的帐号=#radlog_allgroup.acname and tm_upload_all.开户日期> =@startdate then 1 else tm_upload_all.flag1 end,
flag2=case when #radlog_allgroup.acname like tm_upload_all.整理后的帐号+ '% ' and tm_upload_all.开户日期> =@startdate then 1 else tm_upload_all.flag2 end,
fgad2=case when #radlog_allgroup.acname like tm_upload_all.整理后的帐号+ '% ' and tm_upload_all.开户日期> =@startdate then #radlog_allgroup.acname else tm_upload_all.fgad2 end,
flag3=case when tm_upload_all.开户日期> =@startdate and #radlog_allgroup.acname like '% '+ tm_upload_all.整理后的帐号 then 1 else tm_upload_all.flag3 end,
fgad3=case when tm_upload_all.开户日期> =@startdate and #radlog_allgroup.acname like '% '+ tm_upload_all.整理后的帐号 then #radlog_allgroup.acname else tm_upload_all.fgad3 end
from tm_upload_all,#radlog_allgroup
GO
[解决办法]
alter procedure recompair_tm AS
declare @startdate datetime

select @startdate= '07-1-1 '

update A
set A.flag1=1
from tm_upload_all A
where EXISTS(select * from radlog_group where logondatetime> =@startdate AND acname = A.整理后的帐号)
and A.开户日期 > = @startdate

update A
set A.flag2=1,
A.fgad2=B.acname
from tm_upload_all A,(select acname from radlog_group where logondatetime> =@startdate ) B
where B.acname like A.整理后的帐号+ '% '
and A.开户日期> =@startdate

update A
set A.flag3=1,
A.fgad3=B.acname
from tm_upload_all,(select acname from radlog_group where logondatetime> =@startdate ) B
where A.开户日期> =@startdate
and B.acname like '% '+ A.整理后的帐号
GO

热点排行