Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Confusion with CTEs

Author  Topic 

max_tm
Starting Member

4 Posts

Posted - 2008-09-10 : 11:09:13
Hi all, just started using SQL Server yesterday. I have a modest programming background but I am having trouble understanding this particular implementation: http://www.devx.com/dbzone/Article/35550/0/page/1
of percentile calculations. My issue is with:

SELECT
CASE
WHEN t1.salary = t2.salary THEN t1.salary
ELSE t1.salary + (t2.salary - t1.salary) * ((@percentile - t1.curr_rank) / (t2.curr_rank - t1.curr_rank))
END
FROM emp_sal t1, emp_sal t2
...

specifically the last line. Intuitively, I understand this as "run through emp_sal and give us something to refer to it" (in this case t1 and t2). My question is, why do two consecutive applications of emp_sal produce different results? Am I missing something very important about CTEs here .

Thanks!

max_tm
Starting Member

4 Posts

Posted - 2008-09-10 : 11:25:59
Actually, I just figured it out !
Go to Top of Page

Jason100
Starting Member

34 Posts

Posted - 2008-09-12 : 05:30:58
It just can work using a function .
Go to Top of Page
   

- Advertisement -