Skip to content
Advertisement

Recursive Function Compare Values in MS SQL Server

I have a table that has three columns. One is the MemberID, the other column is the score that they got, and the other one is the date when they got the score.

I want to create a result set that is going to show me a list of all the members that improved their scores overtime.

So I think that for this, a recursive table would be the answer. But I don’t know how to create it.

Here is a list of my columns and some values:

In this instance, my result set would only include:

MemberID 2, because it is the only member that improved over time.

Advertisement

Answer

You can use analytic functions rather than recursion to solve this.

If you’re looking for whether the member’s latest score is higher than their earliest score, something like the following should work:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement