Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Identify the first 2 records in a group and annotate

$
0
0

First off, I want to thank everyone for all the support. I really do appreciate all the assistance. What I am trying to do now is identify the first 2 records in a group and annotate them like below.

Source       Identify
Source1		Yes
Source1		Yes
Source1		
Source1	
Source2		Yes	
Source2		Yes	
Source2		
Source2		
Source2		

The records would be sorted by Store and Location and the determining factor for a group is the "Source". With the below, I can get each unique instance in a group.

With CTE as (
select Identify, row_number() over(partition by Source order by ID) as rn
FROM tbl_Eval)

update CTE
set Identify = 1
where rn = 1

I need something similar to above but need to get the top 2. Any assistance would be appreciated.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>