assuming the validation is per HOLEID and the ordering of record is based on [FROM]; with data as( select [HOLEID], [FROM], [TO], [VALUE], [ROW_NO] = row_number() over (partition by [HOLEID] order by [FROM]) from yourtable)select c.*, [GAP] = CASE WHEN c.[TO] = n.[FROM] then 'N' else 'Y' endfrom data c inner join data n on c.[HOLEID] = n.[HOLEID] and c.[ROW_NO] = n.[ROW_NO] - 1
KH[spoiler]Time is always against us[/spoiler]