假如我有两个表,分别是news,guestbookd
这两个表都有字段title
我想通过输入的TextBox1的内容模糊查询title字段在两个表的数据
求解答

解决方案 »

  1.   

    select  字段1,字段2,..... from news where title like '%查询的内容%'
    union all
    select 字段1,字段2,..... from guestbookd where title like '%查找的内容%'注意,两个查询的字段的数量要一致,还有字段的类型
      

  2.   

    建立dataset,把个查询结果度填充到dataset中,或者,自定义一个datatable,把两个标的查询结果,付给datatable中就行了.
      

  3.   

    我有最多60个表需要查询,用的也是union all,多个人同时查询时会有查不到的情况,是什么原因,如何解决,我想放在临时表中,或用存储过程,可以吗
      

  4.   

    用sysobjects这个个去去表名  拼接动态语句
      

  5.   

    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有什么本质区别
      

  6.   

    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
      

  7.   

    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
      

  8.   

    支持存储过程查询,或者你用LINQ