你的意思是把表名设为参数
use ltdb_bak
declare @table varchar(100)
select @table='ltsz_send_log0505'
exec('select count(1), service_id from'+@table+'
where  service_id !=90  and  respond_result=0
group by  service_id'

解决方案 »

  1.   

    hsj20041004(光芒)  那个有点问题哦 不能用啊
      

  2.   

    use ltdb_bak
    @sql='
    select count(1), service_id from '
    +@table+'
     where  service_id !=90  and  respond_result=0
    group by  service_id'
    exec(@sql)
      

  3.   

    @table 和@sql两个都要你再定义一下。
      

  4.   

    ---to yifan600(一剑飘雪) 是谁说的要俩个都申明!!!!》????
    declare @table varchar(100)
    select @table='ltsz_send_log0505'
    exec('select count(1), service_id from'+@table+'
    where  service_id !=90  and  respond_result=0
    group by  service_id')-------缺了个“)”
      

  5.   

    create procedure mm
     @table varchar(100)
    as
     declare @sqlstr varchar(1000)
     select @sqlstr='select count(1), service_id from '+@table+' where  service_id !=90  
                     and  respond_result=0  group by  service_id'
     exec(@sqlstr)
    go
    exec mm 'ltsz_send_log0505'
    如果不用存储过程:
     declare @table varchar(100)
     declare @sqlstr varchar(1000)
     set @table='ltsz_send_log0505'
     select @sqlstr='select count(1), service_id from '+@table+' where  service_id !=90  
                     and  respond_result=0  group by  service_id'
     exec(@sqlstr)