日期:2014-05-17 浏览次数:20615 次
declare @sql varchar(3000) declare @date datetime declare @m varchar(2) declare @d varchar(2) set @date=CONVERT(varchar(10),getdate(),120) set @m=right('0'+cast(DATEPART(M,@date) as varchar),2) set @d=right('0'+cast(DATEPART(D,@date) as varchar),2) set @sql='create table #x(m varchar(7),d varchar(10),ref varchar(1000))'+' while ('+@d+'=15) begin insert into #x(m,d,ref) select top 10 CONVERT(varchar(7),visit_time,120), CONVERT(varchar(10),visit_time,120),left(REFERRER,charindex('''+'/'+''',REFERRER,12)) from WebLog_2012_'+@m+'_'+@d+' where REFERRER like '''+'%.baidu.%'+''' select count(*) from #x set '+@d+'='+@d+'-1 /*这句没有办法更新*/ end select * from #x' exec (@sql)