根据查询结果,例如:
select name from sysobjects where left(name,1)=c and xtype='u'
结果为:
c2014
c2015
这样的
想建立视图
大概就是
select *
from c2014
union all
select *
from c2015
这样的,,,
等于说查询结果是可变的,所以也就是不一定是几个表的union all,因为查询结果,也可能是c2014,c2015,c2016这样的,,这样的视图怎么建立,,,,,
------解决思路----------------------
select LEFT(name,LEN(name)-9) from
(
select
(
select 'select * from ' + name + ' union all '
from sysobjects where left(name,1)='c' and xtype='u'
FOR XML PATH('')
) as name
) a