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

I am trying to convert following Oracle query to SQL Server and having issues in defining calculation in the BETWEEN of the PARTITION.
ORACLE Query:
SELECT  
  head.acct_unit, head.company,head.role_id,    
   AVG(head.HEADCOUNT) over 
      (partition by head.acct_unit, head.company,head.role_id
       order by head.posting_month 
       range between  head.posting_month - trunc(head.posting_month,'YYYY') PRECEDING and current row)  YTD_HEADCOUNT
FROM
TABLE_A head

SQL Server:
SELECT  
  HEAD.ACCT_UNIT, HEAD.COMPANY,HEAD.ROLE_ID, 
  AVG(HEAD.HEADCOUNT) OVER 
      (PARTITION BY HEAD.ACCT_UNIT, HEAD.COMPANY,HEAD.ROLE_ID
       ORDER BY HEAD.POSTING_MONTH 
       -- RANGE BETWEEN DATEDIFF(dd,DATEADD(yy, DATEDIFF(yy,0,HEAD.POSTING_MONTH), 0),HEAD.POSTING_MONTH)
	   --	PRECEDING AND CURRENT ROW
	   )
FROM
TABLE_A head

Any help in this regard is highly appreciated.


Regards,
Shijith
Posted
Updated 27-Aug-14 1:20am
v2
Comments
coded007 28-Aug-14 8:02am    
what is the problem you are getting
Suvendu Shekhar Giri 4-Jan-15 14:09pm    
As far I know, unfortunately UNBOUNDED PRECEDING, UNBOUNDED FOLLOWING, CURRENT ROW etc keywords are not available with SQL Server 2008 R2. These are introduced with SQL Server 2012. So, may be you need to find an work around to resolve your problem without using these keywords. :)

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