"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, April 16, 2011

Dense_Rank() function in SQL Server

 Hi *.*,
In my last post i shown Rank function but in rank function repetition will also count as rank.some times this will not meet our requirement, we need the real count.For this SQL has providing another function Dense_Rank().
SELECT Dense_Rank() OVER (ORDER BY receiptdate ) as Firt_Arrival,locationnumber,receiptdate FROM inventorylocsubdetail


Here Dense_Rank() fn would return the rank based on the ReceiptDate. But this would be in sequence even if there are same rank more than one. (This is the major different between Rank() and Dense_Rank())

E.g: here rank 4 repeating for three records,though next rank is 5 (4,4,4,5)

Hope u got it.If any trouble Ask me.
Stay tune...
Have a nice day... 'N happy Coding :)

No comments: