sql如何将一个ID内一个段号内的内容合并到一起

selectT0.DocNumas订单号,T4.ItemCodeasSAP料号,T3.ItemNameas原料,T0.ItemCodeas产品编号,T0.PlannedQ... select T0.DocNum as 订单号,T4.ItemCode as SAP料号,T3.ItemName as 原料,T0.ItemCode as 产品编号,T0.PlannedQty as 订单数量,T0.U_JT as 机号,T0.U_MJBH AS 模具编号,T0.StartDate as 开工日期,T0.DueDate as 完工日期,T1.U_WLXH as 物料型号,T1.ItemName as 产品名称,T1.U_MJMQ as 模具模腔,T1.U_MZ as 毛重,T2.U_GJG AS 加工周期, U_RS as 人员配置,T4.ItemCode as SAP料号,T4.PlannedQty/1000 原料总重,'注塑' as 工序,cast(cast((1-isnull(T1.U_WLSH,0))*100 as numeric(10,0)) as nvarchar(10))+'%' AS 目标合格率,Case when isnull(T2.U_GJG,0)=0 or isnull(T5.U_Subs,0)=0 then 0 else cast (42000/isnull(T2.U_GJG,0)*isnull(T5.U_Subs,0) as numeric(10,0)) end as 班产定额 from OWOR T0join WOR1 T4 on T0.DocEntry=T4.DocEntryjoin OITM T1 on T0.ItemCode =T1.ItemCodeleft join OCLG T2 on case when isnull(charindex('(',T0.U_MJBH),0)-1>0 then substring(isnull(T0.U_MJBH,''),1,case when cast(isnull(charindex('(',isnull(T0.U_MJBH,'')) ,0) as int)>0 then cast(isnull(charindex('(',isnull(T0.U_MJBH,'')) ,0) as int)-1 else 0 end ) else T0.U_MJBH end=T2.U_MJ and T0.ItemCode=T2.DocNum and T0.U_JT=T2.U_SBBHleft join OITM T3 on T3.ItemCode=T4.ItemCodeleft join [@MOULDDATA] T5 on T5.Code=T2.U_MJwhere t0.Status ='R' AND T1.U_GXMC='I' AND T0.U_OTYPE <>'3'AND (T3.ItemName LIKE '%导杆%' or T3.ItemName LIKE '%插片%')上面是我写的SQL语句,图一是搜索出来的内容,但是当我导入到水晶报表内的时候发现每个订单号只能带出来其中一个原料名称,如图二我想问一下我应该怎么将每个订单号全部带入到水晶报表内,如果需要更改语句的话应该怎么修改? 展开
 我来答
折柳成萌
高粉答主

2017-11-16 · 繁杂信息太多,你要学会辨别
知道顶级答主
回答量:4.4万
采纳率:96%
帮助的人:6185万
展开全部

select distinct b.id, (select ' '+a.text+' ' from table_2 a where a.id=b.id for xml path('')) as text from table_2 b

效果图如下 

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式