Quote:The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
order by newid() <pre lang="sql">select top (4)* from ( select q.Description,q.Ques_Id,ac.ch_number,ac.Choice from Question as q, course as c,Ques_Choice as ac where (q.crs_id = c.crs_id) and (q.Ques_Id=ac.Ques_Id)and (c.crs_name='oop' and q.type=2) order by newid() ) as alr pivot ( min(Choice) for ch_number in (a,b,c,d) ) as pvt union select top (2)* from ( select q.Description,q.Ques_Id,ac.ch_number,ac.Choice from Question as q, course as c,Ques_Choice as ac where (q.crs_id = c.crs_id) and (q.Ques_Id=ac.Ques_Id)and (c.crs_name='oop' and q.type=1) order by newid() ) as alr pivot ( min(Choice) for ch_number in (a,b,c,d) ) as pvt</pre>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)