table_01----保存1月的数据
table_02----保存2月的数据
table_03----保存3月的数据
table_04----保存4月的数据
table_05----保存5月的数据
table_06----保存6月的数据
table_07----保存7月的数据
table_08----保存8月的数据
table_09----保存9月的数据
table_10----保存10月的数据
table_11----保存11月的数据
table_12----保存12月的数据
参数为:
@stime='2007-03-28'---开始时间
@etime='2007-04-02'---结束时间
有什么好办法可以动态指定要查询的两个表

解决方案 »

  1.   

    @stime='2007-03-28'---开始时间
    @etime='2007-04-02'---结束时间
    根据这两个参数来判是哪些表
      

  2.   

    数据不多的话,直接这样:
    select * from 
    (
    select * from table_01
    union
    select * from table_02
    ...
    ..
    .
    union
    select * from table_12
    ) as alltable
    where ....
      

  3.   

    string SQL="select * from(";
    for(int i=DateTime.Pase(stime).Month;i<=DateTime.Pase(etime).Month;i++)
    {
    if(i!=DateTime.Pase(etime).Month)
    {
    SQL+=" select * from table_"+i.ToString("0#")+" union ";
    }
    else
    {
    SQL+=" select * from table_"+i.ToString("0#")+" ) where .........";
    }
    }