sqlserver 存储过程 将左边数据格式转成右边数据格式存放
1个回答
展开全部
数据如下:
这东西不用存储过程,一句话就行了,如下:
with t as
(select SUBSTRING(pbatchno,1,CHARINDEX('-',pbatchno)-1) pbatchno1,SUBSTRING(pbatchno,CHARINDEX('-',pbatchno)+1,LEN(pbatchno)-CHARINDEX('-',pbatchno)) pbatchno2,drawupdepartment,remark from test)
select b.pbatchno1+'-'+left(pbatchno2,LEN(b.pbatchno2)-1) pbatchno,b.drawupdepartment,b.remark
from
(SELECT pbatchno1,
(SELECT pbatchno2+'/' FROM t WHERE pbatchno1=A.pbatchno1 and drawupdepartment=A.drawupdepartment and remark=A.remark FOR XML PATH('')) AS pbatchno2,
drawupdepartment,
remark
FROM t A
GROUP BY pbatchno1,drawupdepartment,remark) b
执行后结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询