Select * from TableName Where ColName Like 'aa-bb-cc%'OrSelect * from TableName Where Left(ColName,8)='aa-bb-cc'

解决方案 »

  1.   

    不是啊  我是要这样的select count(1),sum(fee_code),fee_code from
    aa-bb-cc001
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code这样我只能查出一张表 
    我要一下子查出里面所有的表的内容啊 而不是单单一张aa-bb-cc001
    能用带参数的语法写出来吗??
      

  2.   

    select count(1),sum(fee_code),fee_code from   aa-bb-cc001
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    union all 
    select count(1),sum(fee_code),fee_code from   aa-bb-cc002
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    union all 
    select count(1),sum(fee_code),fee_code from   aa-bb-cc003
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    union all
    select count(1),sum(fee_code),fee_code from   aa-bb-cc004
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    union all 
    select count(1),sum(fee_code),fee_code from   aa-bb-cc005
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    ...
    以下一样
      

  3.   

    晕,“我在系统中有很多这样的”,我还以为是数据叻,没想到是表名。那就用Union Allselect count(1),sum(fee_code),fee_code from
    [aa-bb-cc001]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc002]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc003]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc004]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc005]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc006]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc007]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc008]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
    Union All
    select count(1),sum(fee_code),fee_code from
    [aa-bb-cc009]
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
      

  4.   

    你是要查询所有表中满足这个条件的记录吗??
    你看这样行不行,将表放到一个视图中,你查询直接访问视图。
    Create View List
    As
    Select * from [aa-bb-cc001]
    Union All
    Select * from [aa-bb-cc001]
    Union All
    Select * from [aa-bb-cc002]
    Union All
    Select * from [aa-bb-cc003]
    Union All
    Select * from [aa-bb-cc004]
    Union All
    Select * from [aa-bb-cc005]
    Union All
    Select * from [aa-bb-cc006]
    Union All
    Select * from [aa-bb-cc007]
    Union All
    Select * from [aa-bb-cc008]
    Union All
    Select * from [aa-bb-cc009]
    GO
    Select count(1),sum(fee_code),fee_code from List
    where substring(mtid,5,3)='999' and respond_result=0
    group by fee_code
      

  5.   

    每张表都是几十万条数据的话,Union All会拖死的,如果你的表名固定为aa-bb-cc加上001这种模式,或者事先可以根据条件判断在哪张表,建议在程序里拼一下表名,然后作为一个参数传进来,不一定非要在存储过程解决。