set @name=''
select top 10 @name+='['+prod_sname+'],' from PRODUCT
set @name=left(@name,LEN(@name)-1)
--
declare @sql1 varchar(max)
set @sql1='
select * from (
select top 10 prod_bar,prod_sname,sale_price from PRODUCT ) as v1
pivot
(
sum(sale_price) for prod_sname in ('+@name+')
) as vp1 '
exec(@sql1)
沒有留言:
張貼留言