select * from 发票单200410 
union all ----##
select * from 发票单200411

解决方案 »

  1.   

    加上Union All就可以。Select * from 发票单200410 
    Union All
    Select * from 发票单200411
      

  2.   

    同意union all 
    但是请教 union all会合并相同记录吗?
      

  3.   

    同意union all
    但是如果两个表里有重复记录怎么办?
      

  4.   

    同意union all 
    但是请教 union all会合并相同记录吗?
    -------------------------------------------------------
    union all 不会合并相同记录,如果要合并重复记录,用Union
      

  5.   

    to  iuhxq(小灰) union all   相同记录共同(重复)存在
    union  相同记录只留一个~~~
      

  6.   

    --a
    建議在後台建一個視圖:視圖內容如下:
    create view find_发票单
    select * from 发票单200410
    union all
    select * from 发票单200411
    union all
    select * from 发票单200412
    union all
    ...
    select * from 发票单200504
    go------b
    以後在前台可以用以下語句就可以了:
    select * from find_发票单 where 號碼='20040101001'--c
    以後要加表的話只要修改後台視圖就可以了,與前台查詢語句無關,這樣方便移植.
     
      

  7.   

    但是请教 union all会合并相同记录吗?
    --------union all-----不压缩重复纪录,不排序
    union    -----合并重复纪录,并排序
      

  8.   

    谢谢上面几位朋友指点那如果按某个列排序怎么写?order by 列名就可以吗?一定要求两个表的列名相同吧?
      

  9.   

    我认为可以列名不一样
    select a as 列名 from 表1
    union 
    select b as 列名 from 表2试试看
    union 一样!
      

  10.   

    用union或union all做一个试图
      

  11.   

    select * from 发票单200410 
    union all
    select * from 发票单200411
    這樣不就行了
      

  12.   

    --a
    建議在後台建一個視圖:視圖內容如下:
    create view find_发票单
    select * from 发票单200410
    union all
    select * from 发票单200411
    union all
    select * from 发票单200412
    union all
    ...
    select * from 发票单200504
    go那如何更新视图呢?比如定义了一个包含了从发票单200410-发票单200504的一个视图,到了5月份时候,如何把发票单200505加上去?用什么语句啊?
      

  13.   

    paoluo(一天到晚游泳的鱼) ,我不是更新表(不是说再表里加数据),而是增加一整个的表,一个月一张表,结构相同,如何更新视图呢?
      

  14.   

    那就在这
    create view find_发票单
    select * from 发票单200410
    union all
    select * from 发票单200411
    union all
    select * from 发票单200412
    union all
    ...
    select * from 发票单200504
    go
    后面加上
    union all
    select * from 发票单200505
    即可完整语句为
    create view find_发票单
    select * from 发票单200410
    union all
    select * from 发票单200411
    union all
    select * from 发票单200412
    union all
    ...
    select * from 发票单200504
    union all
    select * from 发票单200505
    go
      

  15.   

    paoluo(一天到晚游泳的鱼)你的意思是每次都把以前的表名都写一遍,好像有些麻烦?能不能如下这样呢?
    create view find_发票单
    select * from fingd_发票单
    union all
    select * from 发票单200505
    go???
      

  16.   

    paoluo(一天到晚游泳的鱼),可是如果是在前台和后台的应用上还是有问题,作为管理员(后台),我当然可以用复制一下加代码,可是,如果是在应用程序的人员(前台),那怎么能用复制一下加代码?表的增加是随着客户端动态的变化的.而不是我在sql sever里改变他
      

  17.   

    嘿,不好意思,没想到这个问题。再THINKING。
      

  18.   

    --这一系列表的名字如果有规律的话就可以实现--假设这些表都是tb开头的,后面加数字declare @sql varchar(8000)
    set @sql='select * from 'select @sql=@sql+name+' union all select * from ' from sysobjects where name like 'tb%' and xtype='U' order by nameset @sql=left(@sql,len(@sql)-25)exec @sql
      

  19.   

    --这一系列表的名字如果有规律的话就可以实现--假设这些表都是tb开头的,后面加数字declare @sql varchar(8000)
    set @sql='select * from 'select @sql=@sql+name+' union all select * from ' from sysobjects where name like 'tb%' and xtype='U' order by nameset @sql=left(@sql,len(@sql)-25)exec(@sql)
      

  20.   

    lxd99423(苹果),强,真是强,除了set @sql=left(@sql,len(@sql)-25)这个25改成24外,其他都对了,100分里应该得90分了!!!!没有想到这个 select @sql = @sql + name + ........可以返回一下这个结果!就像做了个for 循环一样,而且循环次数又以记录的数量做决定!这是我做梦都没有想到的,佩服!!!!!select * from 進貨單200012 union all select * from 進貨單20011 union all select * from 進貨單20012 union all select * from 進貨單200212 union all select * from 進貨單200310 union all select * from 進貨單20033 union all select * from 進貨單20038 union all select * from 進貨單20039 union all select * from 進貨單20041 union all select * from 進貨單200410 union all select * from 進貨單200411 union all select * from 進貨單200412 union all select * from 進貨單20042 union all select * from 進貨單20043 union all select * from 進貨單20044 union all select * from 進貨單20045 union all select * from 進貨單20046 union all select * from 進貨單20047 union all select * from 進貨單20048 union all select * from 進貨單20049 union all select * from 進貨單20051 union all select * from 進貨單20052 union all select * from 進貨單20053 union all select * from 進貨單20054 union all select * from 進貨單20055 union all select * from 進貨單20073 union all select * from 進貨單20083 union all select * from 進貨單資料