Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Hierarical Query Performance

$
0
0

Hi Folks,

I need a quick help from you. I have a hierarical query that is used in the front-end application.

WITH EMP ([EMP_ID],[NAME],  [MANAGER_NAME]  ,[MANAGER_ID], [CHGS]) AS 

(   SELECT [EMP_ID],[NAME],[MANAGER_NAME]  ,[MANAGER_ID], [CHGS]  FROM EMPLOYEE
 WHERE [MANAGER_ID]=101 or [EMP_ID]=101 and  BILLDATE  BETWEEN '10-APRIL-2013' and '10-MAY-2013'
  UNION all  
SELECT a.[EMP_ID], a.[NAME], a.[MANAGER_NAME]  ,a.[MANAGER_ID], a.[CHGS] FROm EMPLOYEE as a inner  JOIN EMP b ON a.[MANAGER_ID]=b.[EMP_ID]) 

SELECT round(sum(distinct([CHGS]))/100,0) as charges FROM EMP.

In Employee table there were 2000 records and it is taking 6 minutes.

Can you kindly suggest me how to improve the performance of this query. Appreciate your help.

Thanks,

Ven.


Viewing all articles
Browse latest Browse all 12963

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>