--用临时表 select a.id,a=cast('' as varchar(8000)),b.[status-chinese] into #t from talbe1 a,table2 b where a.[status-id]=b.[status-id] order by a.id,b.b.[status-id]declare @id varchar(10),@s varchar(8000) update #t set @s=case @id when id then @s+'/'+[status-chinese] else [status-chinese] end ,a=@s,@id=id select id,[status-chinese]=max(a) from #t group by id
题中已写明需要的结果。
select a.id,a=cast('' as varchar(8000)),b.[status-chinese]
into #t from talbe1 a,table2 b
where a.[status-id]=b.[status-id]
order by a.id,b.b.[status-id]declare @id varchar(10),@s varchar(8000)
update #t set @s=case @id when id then @s+'/'+[status-chinese] else [status-chinese] end
,a=@s,@id=id
select id,[status-chinese]=max(a)
from #t
group by id
但,我的table1在不断增大,而要得结果去不断生成临时表,有很麻烦。
zjcxc(邹建)有更好的方法吗??
比如存储过程,之类的解决方法。