TA的每日心情 | 开心 2023-8-25 08:56 |
---|
签到天数: 635 天 [LV.9]以坛为家II
|
发表于 2011-5-12 12:28:52
|
显示全部楼层
公司业务库上用的过程和用法,希望对你有所帮助,附件主用到的取表名过程。
declare @BeginDate datetime;
declare @EndDate datetime;
declare @SQLString char(8000);
declare @tables char(1024);
declare @subTableName char(32);
declare @i int;
select @BeginDate='20100101',@EndDate='20100501'
exec gettablesname @BeginDate,@EndDate,data,@tables output;
select @tables as tablesname into #tablename
while 1=1 begin
select @i=charindex(',',tablesname) from #tablename;
print (@i)
select * From #425103tablename
if @i=0 begin select @subTableName=tablesname from #425103tablename;
select @SQLString='insert into #201102data
select * from '
+ ltrim(rtrim(@subTableName))
+ ' a where convert(varchar(10),Sdate,120)>='''
+ convert(varchar(10),@begindate,120)
+ ''' and convert(varchar(10),Sdate,120)<='''
+ convert(varchar(10),@enddate,120)
+ '''
';
print(@SQLString);
-- execute (@SQLString);
break;
end
else begin
select @subTableName=substring(tablesname,1,charindex(',',tablesname)-1) from #425103tablename;
select @SQLString='insert into #201102data
select * from '
+ ltrim(rtrim(@subTableName))
+ ' a where convert(varchar(10),Sdate,120)>='''
+ convert(varchar(10),@begindate,120)
+ ''' and convert(varchar(10),Sdate,120)<='''
+ convert(varchar(10),@enddate,120)
+ '''
';
print(@SQLString);
-- execute (@SQLString);
update #425103tablename set tablesname=substring(tablesname,charindex(',',tablesname)+1,len(tablesname)) where 1=1;
end;
end;
|
|