FYI with that kind of table design you are violating the basic form of normalisation i.e the 1NF.I would highly recommend to you to change it if you can.Anyways below will give you a basic idea on how to get your desired o/p.declare @tbl as table(id int identity(1,1),col1 int,col2 int,col3 int)insert into @tblselect 1,2, 5 union allselect 4,1, 3select * from @tblselect id,MAX(col)MaxValue from( select * from ( select * from @tbl )u unpivot (col for NullColumns in(col1,col2,col3))v )T group by id
Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH