22,210
社区成员
发帖
与我相关
我的任务
分享
declare @s varchar(8000),@d1 datetime,@d2 datetime
select @d1='2008-1-1',@d2='2008-2-5' --设指定的时段为 2008-1-1 至 2008-2-5
select @s=isnull(@s + '] union all select * from [',' select * from [') + name from sysobjects
where xtype='u' and case when isdate(name)=1 then name else '1900-1-1' end between @d1 and @d2
exec( @s+']')
--如果有条件的查询
exec('select * from (' + @s + ']) x where 字段名=''值''')
declare @s varchar(8000)
select @s=isnull(@s + '] union all select * from [',' select * from [') + name from sysobjects where isdate(name)=1 and xtype='u'
exec( @s+']')
--如果有条件的查询
exec('select * from (' + @s + ']) x where 字段名=''值''')
select * from(
select * from [2008-9-1]
union all
select * from [2008-9-2]
)a
where 日期字段 between .... and ...