Akhter HUssain

Akhter HUssain

  • 653
  • 1.3k
  • 95.6k

Msg 102, Level 15, State 1, Line 22 Incorrect syntax near 'order'.

Sep 19 2020 7:12 AM

When i am executing below query in sql 2008 then it giving below error,

Msg 102, Level 15, State 1, Line 22
Incorrect syntax near 'order'.

,But when i am executing in sql 2014 it is working fine,with same data ,what could be the issue.
 
  1. WITH CTE  
  2.   AS(SELECT     isnull(CustomerItem.CIName,ItemMasterFile.Descriptionitem) as Descriptionitem,sum(tbl_PckDetail.QTY) as QY,  
  3.    (isnull(Probale.PBSize,itemmasterfile.weight)) as WT,(sum(tbl_PckDetail.QTY)*isnull(Probale.PBSize,  
  4.    itemmasterfile.weight))as Total_wt,('x '''+' '''+ ItemMasterFile.BaleSize) ITEM,  
  5.               
  6.    CAST((isnull(nullif(isnull(Probale.PBSize,itemmasterfile.weight),0)*sum(tbl_PckDetail.QTY)/nullif(2.2046,0),0))  as decimal(18,0)) Kg  
  7.    FROM         tbl_SBDispatachD  
  8.    inner join tbl_PckDetail on tbl_PckDetail.PID=tbl_SBDispatachD.PID  
  9.    inner join ItemMasterFile on ItemMasterFile.CodeItem=tbl_PckDetail.Codeitem  
  10.               
  11.    inner join   SalesOrder ON SalesOrder.OrderNo = tbl_PckDetail.OrderNo   
  12.       left join CustomerItem on CustomerItem.Codeitem=tbl_PckDetail.Codeitem   
  13.                          and CustomerItem.CustomerID=SalesOrder.Customerid  
  14.               
  15.               
  16.      left outer join Probale on Probale.prdno=tbl_PckDetail.Prdno  
  17.       and ItemMasterFile.CodeItem=Probale.codeitem  
  18.               
  19.    where tbl_SBDispatachD.ID =1109 and tbl_PckDetail.DelID is null and tbl_SBDispatachD.Del is null   
  20.    group by  CustomerItem.CIName,ItemMasterFile.Descriptionitem ,Probale.Pbsize,ItemMasterFile.weight ,ItemMasterFile.BaleSize)  
  21.           
  22.   ,cte2 as(SELECT Descriptionitem,SUM (QY) OVER(PARTITION BY Descriptionitem ORDER BY Descriptionitem) QY,SUM (WT) OVER(PARTITION BY Descriptionitem ORDER BY Descriptionitem)WT,  
  23.          SUM (Total_wt) OVER(PARTITION BY Descriptionitem ORDER BY Descriptionitem) Total_wt,Item,SUM (kg) OVER(PARTITION BY Descriptionitem ORDER BY Descriptionitem)kg  
  24.          FROM CTE)    
  25.   ,cte3 as(select *,row_number() over(partition by Descriptionitem order by Descriptionitem)rn from cte2)  
  26.           
  27.   select * from cte3 where rn<2  
 

Answers (1)