select a,b,c into #tb from table union select a,b,c into #tb2 from table2union前後的語句都可以單獨運行,但是加上union一起的話就報錯;錯誤提示:SELECT INTO must be the first query in a statement containing a UNION, INTERSECT or EXCEPT operator.

解决方案 »

  1.   


    select a,b,c into #tb from table 
    select a,b,c into #tb2 from table2select * from #tb
    union
    select * from #tb2
      

  2.   

    select a,b,c into #tb from table 是创建表并且插入数据,并不是查询结果而union 是取那个结果集的并集 ,所以不能这样写
      

  3.   


    謝謝您的回答但這樣會報錯:The ntext data type cannot be selected as DISTINCT because it is not comparable。謝謝。
      

  4.   


    select a,b,c into #tb from table 
    select a,b,c into #tb2 from table2select * from #tb
    union all --不过滤重复数据了
    select * from #tb2
      

  5.   

    不能带着into 进行 union。