select 字段1,字段2,..... from news where title like '%查询的内容%' union all select 字段1,字段2,..... from guestbookd where title like '%查找的内容%'注意,两个查询的字段的数量要一致,还有字段的类型
delcare @sql varchar(max) select @sql=isnull(@sql+'union ','')+'select * from '+name from sys.object where right(name,8) between @begintime and @endtime exec(@sql)这个与直接用union all有什么本质区别
create proc P_title as begin set nocount on declare @str varchar(max)='' create table #tb(你所要的字段) select @str=@str+CHAR(10)+'insert into #tb select 你所要的字段 from '+name+' where title like ''%查询的内容%'' ' from sysobjects where type='u' exec(@str) end sel
create proc P_title as begin set nocount on declare @str varchar(max)='' create table #tb(你所要的字段) select @str=@str+CHAR(10)+'insert into #tb select 你所要的字段 from '+name+' where title like ''%查询的内容%'' ' from sysobjects where type='u' exec(@str) select * from #tb end
union all
select 字段1,字段2,..... from guestbookd where title like '%查找的内容%'注意,两个查询的字段的数量要一致,还有字段的类型
select @sql=isnull(@sql+'union ','')+'select * from '+name from sys.object
where right(name,8) between @begintime and @endtime
exec(@sql)这个与直接用union all有什么本质区别
as
begin
set nocount on
declare @str varchar(max)=''
create table #tb(你所要的字段)
select @str=@str+CHAR(10)+'insert into #tb select 你所要的字段 from '+name+' where title like ''%查询的内容%'' ' from sysobjects where type='u'
exec(@str)
end
sel
as
begin
set nocount on
declare @str varchar(max)=''
create table #tb(你所要的字段)
select @str=@str+CHAR(10)+'insert into #tb select 你所要的字段 from '+name+' where title like ''%查询的内容%'' ' from sysobjects where type='u'
exec(@str)
select * from #tb
end