sql 一个字段有多条数据 在一行显示
selectb.f_measurefromt_quality_qi_specialt,t_quality_qi_measurebwheret.f_id=b.f_speci...
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 查询出 两条记录
将其结果 显示 为 1224 ,122 不甚感激 展开
将其结果 显示 为 1224 ,122 不甚感激 展开
2个回答
展开全部
方法一:直接构造(这种方法针对这样的问题比较好,但实用性不大)
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
2015-04-14
展开全部
DECLARE @str NVARCHAR(1000)
SET @str = ''
select @str += 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
SELECT @str
--2008
SET @str = ''
select @str += 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
SELECT @str
--2008
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询