Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

The following is my pivot table query.

select * from (select StudnetAdmissionNumber,23011 as Tamil,23012 as English,2013 as Maths,2014 as Science,2015 as SocialScience from Mark_details)x pivot (max(MarkObtained) for SubjectId in ('23011','23012','23013','23014','23015'))p


and the error is
Incorrect syntax near '23011'.


subjectId datatype is varchar(30)

what is the problem?
Posted

1 solution

Hi,

Try like this.

select * from (select StudnetAdmissionNumber,
			23011 as Tamil,
                        23012 as English,
                        2013 as Maths,
                        2014 as Science,
                        2015 as SocialScience 
                        from Mark_details) x 
                        pivot (max(MarkObtained) for SubjectId in ('23011','23012','23013','23014','23015')) AS p


Thanks
 
Share this answer
 
Comments
baskaran chellasamy 19-Dec-12 6:11am    
I tried the above you said,but still error near in ('23011'
[no name] 19-Dec-12 6:18am    
can you tell me the datatype of your subjectID?
baskaran chellasamy 19-Dec-12 6:21am    
varchar(30) and when i make a cursor on error it display expected ID or quoated ID or '.'.
[no name] 19-Dec-12 8:19am    
Can you tell me what are the following numbers in your table?

23011 as Tamil,
23012 as English,
2013 as Maths,
2014 as Science,
2015 as SocialScience
baskaran chellasamy 22-Dec-12 6:18am    
yes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900