行转换列的列数目!!!!
行转换列的存储过程
ALTER PROCEDURE [dbo].[c_p_dj]
(
@bj nvarchar(100)
)
AS
declare @sql nvarchar(1000)
select @sql=isnull(@sql+',','')
+'max(case djplace when '''+djplace+''' then djcode else NULL end) as ['+djplace+']'
from (select distinct djplace from c_v_dj1 where jcmodel=@bj) as a
set @sql='select jccode,'+@sql+' from c_v_dj1 where jcmodel='''+@bj+''' group by jccode'
exec(@sql)