create table #i ( i int, j int, k int) insert #i values(1, 2, 3) insert #i values(1, 3, 2) insert #i values(2, 1, 3) insert #i values(2, 3, 1) insert #i values(3, 1, 2) insert #i values(3, 2, 1) insert #i values(1, 2, 1) insert #i values(1, 1, 1) insert #i values(1, 0, 1) select (case when (i <= j and i <= k) then i when j <= k then j else k end) from #i