日期:2014-05-17 浏览次数:20546 次
Declare @SQLStatement VarChar(Max)
/*这个初始化一个物品信息表,大概5-6秒左右*/
Exec SP_Initialize '##ItemInfo',' and SellMonth in (Select Distinct Top 2 Month(SellDate) from ItemSellInfo Order By SellDate Desc)'
/*这里从MstGridCol表中取字段并组合,比如组合后是
Select 'Sell' As ProcessClass,b.ItemClass,a.ItemName,c.PayState
*/
Set @SQLStatement='Select 'Sell' As ProcessClass'
Select @SQLStatement=@SQLStatement+','+DataField from MstGridCol where Formname='ItemSellInfo' And GridName='Detail2'
/*这里从GridSQLStatement 取form之后的表组合字符串,比如组合后是
from ItemCSC a inner join MstItemClass on a.ItemClass=b.ItemClass Left join ItemPayInfo c on a.PayMonth=c.PayMonth where a.ItemType='Online'
*/
IF Exists (select Name from Tempdb..SysObjects where Name='##Reuslt') Drop Table ##GarProdInqCSC
Select @SQLStatement=@SQLStatement+' Into ##Reuslt '+SQLStatement from GridSQLStatement where Formname='ItemSellInfo' And GridName='Detail2'
/*组合后执行,由于表数量过多,数据量大,所以组合后执行时间大概为60秒以上*/
Exec (@SQLStatement)
IF Exists (select Name from SysObjects where Name='ItemCSC') Drop Table ItemCSC
Exec ('Select * Into ItemCSC from ##Reuslt')
Exec (@SQLStatement)
WAITFOR DELAY '00:02:00'
IF Exists (select Name from SysObjects where Name='ItemCSC') Drop Table ItemCSC
Exec ('Select * Into ItemCSC from ##Reuslt')
exec(@SQLStatement)
while object_id('tempdb..##Reuslt') is null
begin
if object_id('tempdb..##Reuslt') is not null
break
end
if exists(select 1 from sysObjects&nbs