Friday, June 18, 2010

ROW_NUMBER Function in T-SQL.

A Sample query with out a Row Number function:
The result set for the above query:


Now, lets see the query with Row Number Function..


And the Result Set..


Now When we use joins, we can use the query with Row Number Function and get the most recent Lock for any particular loan.

Query with joins..

And the Result..


Now If we did not use the Row Function in the Join Statement, we would have end up with multiple LoanID's with all the locks that were ever placed on that Loan. But now, using this Row Number Function, we were able to get only the most recent lock which we need.

No comments:

Post a Comment