declare @sql varchar(8000)
set @sql = 'select sm,isbn,name,kb,cbs,flh,bdd '
select @sql = @sql + ' , max(case gys_name when ''' + gys_name + ''' then jg else 0 end) [' + gys_name + ']'
from (select distinct gys_name from ZC_BJD_MX_VIEW) as a
set @sql = @sql + ' from ZC_BJD_MX_VIEW group by sm,isbn,name,kb,cbs,flh,bdd'
use databasename
create view view_name as exec(@sql)
你试试,我没试过