2024-11-05 07:28:37
方法一:直接构造(这种方法针对这样的问题比较好,但实用性不大)
DECLARE @result VARCHAR(1024)
SET @result = ''
select @result += b.f_measure+',' from t_quality_qi_special t , t_quality_qi_measure b where t.f_id=b.f_special_sn and t.f_id=4 and b.f_is_active=1
set @result=substring(@result,1,len(@result)-1)
SELECT @result
方法二:游标遍历(这种方法可适用性比较强,但是看起来比较麻烦)
declare @result varchar(1024) ='',@lsf_measure varchar(1024)
declare cursor_test cursor for select b.f_measure
from t_quality_qi_special t , t_quality_qi_measure b
where t.f_id=b.f_special_sn and t.f_id=4 and b.f_is_active=1
open cursor_test
fetch next from cursor_test into @lsf_measure
while @@fetch_status=0
begin
if len(@result)>=1
set @result=@result+','+@lsf_measure
if len(@result)<1
set @result=@lsf_measure
fetch next from cursor_test into @lsf_measure
end
close cursor_test
deallocate cursor_test
select @result
2024-11-05 00:13:49