日期:2014-05-17 浏览次数:20421 次
declare @sql varchar(8000)
set @sql = ''
select @sql=@sql +',['+a.cdate+']=isnull(SUM(CASE a.cdate WHEN '''+a.cdate+''' THEN rtrim(a.iQuantity) ELSE '''' END),'''')'
from #temp_table a group by a.cdate
set @sql = 'select b.cCusCode 客户编码,b.cCusName 客户名称,b.cInvCode 存货编码,b.cInvName 存货名称,b.cInvCName 存货分类,b.cSTName 销售方式 '+@sql+', sum(a.iQuantity) 销售订单数
from #temp_table a
join #temp_table_2 b on a.cCusCode=b.cCusCode and a.cInvCode=b.cInvCode
group by a.cCusCode,b.cCusCode,b.cCusName,a.cInvCode,b.cInvCode,b.cInvName,b.cInvCName,b.cSTName '
exec(@sql)