要把A类,B类显示在同一行,要对结果再用游标进行合并了--读取数据,放入临时表#tempselect 编码,类别 into #temp from Table1 where 编码 in (select 编码 from TABLE1 group by 编码 having count(*)>=2)--构造临时表#result,类别字段这里要变大,因为是很多加在同一行的,select distinct 编码,类别=convert(nvarchar(2000),null) into #result from #temp order by 编码 ASC--设为空,为了后面不用isnull()...update #result set 类别=''declare @NumberValue nvarchar(50),@TypeValue nvarchar(50)declare Number_Cursor cursor forselect 编号, 类别 from #tempopen Number_Cursorfetch next from Number_Cursor into @NumberValue, @TypeValuewhile @@FETCH_STATUS = 0begin update #result set 类别=类别+' '+@TypeValue where 编号=@NumberValue fetch next from Number_Cursor into @NumberValue, @TypeValueendclose Number_Cursordeallocate Number_Cursor--去掉前置空格update #result set 类别=ltrim(类别)--输出结果select * from result--删除临时表drop table #tempdrop table #result