有两个表,分别是Table1和Table2
Table1有字段A,Table2有字段B,A字段和B字段类型都是nvarchar型,长度一样。现要把这两个表中A、B字段的内容读出来,合并成一个新表Table3,这个表只有一个字段C,类型是nvarchar,值是A+B。请问这个SQL语句怎么写啊?

解决方案 »

  1.   

    Table3其实就是Table1和Table2两个表的总和。
      

  2.   

    select c into table3 from
    (
    select a+b c from table1
    union all
    select a+b c from table2
    ) t
      

  3.   

    --如果table3不存在
    select c into table3 from
    (
    select a+b c from table1
    union all
    select a+b c from table2
    ) t 
     
    --如果table3存在
    insert into table3
    select a+b c from table1
    union all
    select a+b c from table2 
      

  4.   

    --如果table3不存在
    select c into table3 from
    (
    select a+b c from table1 cross table2) t  
     
    --如果table3存在
    insert into table3
    select a+b c from table1 cross table2