2
Answers

what is the error

Hi friends
  This is my query

ALTER procedure [dbo].[sp_getmarkforclass](@classid int,@examid int)
as
begin
declare @paramlist varchar(max),@query nvarchar(max)
set @paramlist=STUFF((select distinct ',[' + SubjectId + ']' from School.dbo.Mark_details where classid=@classid and ExamId=@examid for xml path('')),1,1,'')
print @paramlist
set @query='select * from(select '+ @paramlist +' from School.dbo.Mark_details) p PIVOT(sum(MarkObtained)for SubjectId IN ('+@paramlist+')) AS pvt'
exec @query 
end

GO
 
and the error is

Msg 203, Level 16, State 2, Procedure sp_getmarkforclass, Line 8
The name 'select * from(select [23011],[23012],[23013],[23014],[23015] from School.dbo.Mark_details) p PIVOT(sum(MarkObtained)for SubjectId IN ([23011],[23012],[23013],[23014],[23015])) AS pvt' is not a valid identifier.

Answers (2)