declare @sql varchar(8000)
set @sql = 'select 合营标识,数据类型,报表收敛一层,'
select @sql = @sql + 'sum(case year_month when '''+year_month+'''
then USD else 0 end) as '''+year_month+''','
from (select distinct year_month from 合营数据) as a
select @sql = left(@sql,len(@sql)-1) + ' from 合营数据 group by 合营标识,数据类型,报表收敛一层'
exec(@sql)
go执行上述语句后,只提示"Command(s) completed successfully.",怎么看不到查询结果?

解决方案 »

  1.   

    exec执行前print下,把print出来的语句执行看。
      

  2.   

    不好意思,我是新手,我不明白你所说的print是指?
      

  3.   


    declare @sql varchar(8000)
    set @sql = 'select 合营标识,数据类型,报表收敛一层,'
    select @sql = @sql + 'sum(case year_month when '''+year_month+'''
    then USD else 0 end) as '''+year_month+''','
    from (select distinct year_month from 合营数据) as a
    select @sql = left(@sql,len(@sql)-1) + ' from 合营数据 group by 合营标识,数据类型,报表收敛一层'
    print @sql---l楼说的是在这里添加print,查看你sql语句,看看是否有结果
    --exec(@sql)
    go
      

  4.   


    then USD else 0 end) as '''+year_month+''','-----then USD else 0 end) as year_month,'
      

  5.   

    看sql的消息,比如:
    “select 合营标识,数据类型,报表收敛一层,sum(...)”这样检查下你的sql语句是否有问题……