1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
select * , CASE rn2 WHEN 1 THEN convert(varchar(20), Loyal) ELSE '' end as Loyal3 ,CASE when Loyalt>'0' ,count(*) over (partition by Dept) from tempPaged where Dept = 'Grocery' And totrow >= @Lower AND totrow <= @Upper