I have this attempt to have a case in the where clause:
WHERE CASE WHEN sg.storecode = 'Y1' THEN sg.storecode
ELSE sg.storecode END = sg.storecode
I know it's not correct but I don't know how to code this. Basically what I want to do is if there are two records with storecode 'Y1' and 'S1', always get the record with the 'Y1'.
select top(1) with ties
[number]
,[year]
,[level]
,storecode
from yourtable
order by row_number() over(partition by [number]
,[year]
,[level]
order by storecode desc
)