Implementing Multilevel Ranking in T-SQL

You might have a table with different PEOs for each Company ID. For example:

 Table name : tblRankingCid         peo----------- -----------1           200003311           200006301           200009301           200012312           200003312           200006302           200009302           20001231

To give PEO ranking for each CompanyId, add one column, say “Rank” to the present table and use the following script:

 --///////////////////////////////////////ALTER TABLE tblRanking ADD Rank int NULLdrop table #fiddeclare @Start intdeclare @FID intselect @Start = 0select distinct fid into #fid from tblRankingupdate t1 set @Start = Rank = case when t1.fid = @FID then @Start + 1 else1 end,@fid = t2.FID from tblRanking t1 ,#fid t2 where t1.fid = t2.fidselect * from tblRanking--///////////////////////////////////////fid         peo         rank----------- ----------- -----------1           20000331    11           20000630    21           20000930    31           20001231    42           20000331    12           20000630    22           20000930    32           20001231    4

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may

man on floor with data

DevX Quick Guide to Data Ingestion

One of the biggest trends of the 21st century is the massive surge in internet usage. With major innovations such as smart technology, social media, and online shopping sites, the internet has become an essential part of everyday life for a large portion of the population. Due to this internet