SQL存储过程做成视图
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL存储过程做成视图相关的知识,希望对你有一定的参考价值。
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'
exec(@sql)
把上面的SQL做成视图显示出来
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)
你试试,我没试过
存储过程和视图的区别
以上是关于SQL存储过程做成视图的主要内容,如果未能解决你的问题,请参考以下文章