Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
select case when h.VVID<=15 then COUNT(h.fs) end as [<=15],
case when h.VVID between 16 and 18  then COUNT(h.fs) end as [16 - 18],
case when h.VVID between 19 and 21 then COUNT(h.fs) end as [19 - 21],
case when h.VVID between 22 and 24 then COUNT(h.fs) end as [22 - 24],
case when h.VVID>=25 then COUNT(h.fs) end as [>=25]
from
(
select t.fs,sum(t.VVID) VVID,sum(t.VID) VID,sum(t.ID) ID from
(
select dr.C_FS_Code fs,

case when ds.c_doc_grade='G00001'  then COUNT(distinct ds.C_DSC_Code) end as [VVID],

case when ds.c_doc_grade='G00002'  then COUNT(distinct ds.C_DSC_Code) end as [VID],

case when ds.c_doc_grade='G00003'  then COUNT(distinct ds.C_DSC_Code) end as [ID]

from tbl_dwr dr

join tbl_dwr_details ds on ds.N_Srno=dr.N_Srno

join Tbl_FS_Mst fs on fs.C_Code=dr.C_FS_Code

join Tbl_Doc_Stock_Chem_Add_Mst sd on sd.C_Code=ds.C_DSC_Code

where MONTH(dr.D_Date_Report) in (3,4) and YEAR(dr.D_Date_Report)=2015

and fs.N_Type=1
--and dr.C_FS_Code='MSR001'
group by dr.C_FS_Code,ds.c_doc_grade
)t
group by t.fs
order by t.fs
)h



after executing this query am getting error like in below

Msg 1033, Level 15, State 1, Line 34
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

please give solution for this...
Posted
Comments
King Fisher 11-May-15 8:34am    
Remove the Order by Clause,place it outside the query

1 solution

The error should be pretty clear. You have an ORDER BY statement in your derived table (nested query). You have ORDER BY t.fs but that is inside the h derived table.

Either remove the order by and put it on the outside, after )h or add SELECT TOP 100 PERCENT Case...
 
Share this answer
 

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