sql server 2008 Pivot View -
create view vw_sub declare @cols nvarchar(max), @query nvarchar(max) select @cols = stuff((select ',' + quotename(subjectname) vw_subtem classid=1 , schoolid=4 , sectionid=1 group subjectname, id order id xml path(''), type ).value('.', 'nvarchar(max)') ,1,1,'') set @query = 'select ' + @cols + ' ( select subjectname vw_subtem ) x pivot ( max(subjectname) subjectname in (' + @cols + ') ) p ' execute(@query) go
i have err"incorrect syntax near keyword 'declare'." @ time create view plz give me solution how create view of this
a view has single select statement. can read on in definition of create view sql server 2008.
more formally syntax is:
create view [ schema_name . ] view_name [ ( column [ ,...n ] ) ] [ <view_attribute> [ ,...n ] ] select_statement [ check option ] [ ; ]
you can see create view select_statement. can supply select statement, , no more.
if require dynamic sql generate statement, option use stored procedures.
Comments
Post a Comment