日期:2014-05-18 浏览次数:20401 次
declare @T table (ID int,Description varchar(2)) insert into @T select 1,'aa' union all select 2,'bb' union all select 3,'cc' union all select 3,'c' union all select 3,null union all select 4,'dd' union all select 5,null union all select 6,'ee' union all select 6,'e' union all select 7,'ff' union all select 7,'f' union all select 7,null union all select 8,'gg' select ID,Description= isnull((select top 1 Description from @T where ID=t.ID order by len(Description) desc),'') from @T t group by ID /* ID Description ----------- ----------- 1 aa 2 bb 3 cc 4 dd 5 6 ee 7 ff 8 gg */