时间:2021-07-01 10:21:17 帮助过:4人阅读
这里的列针对的是int 型,所以要转换。
针对订单那种订单主从表,从表多个的名称拼接在一起的
--实例1 分割符在前 select isnull ((select ‘@‘+ CommodityName from OrderInfo where OrderInfo.orderid =OrderMain.OrderID for xml path(‘‘)),‘‘) from OrderMain where orderid =‘20120302121548‘ --针对分隔符在前,可以用stuff很方便 select isnull (stuff((select ‘@‘+ CommodityName from OrderInfo where OrderInfo.orderid =OrderMain.OrderID for xml path(‘‘)),1,1,‘‘),‘‘) from OrderMain where orderid =‘20120302121548‘ --实例2 同表,分隔符在后 SELECT distinct vcName,dtCreateTime, ISNULL ((select CONVERT(VARCHAR(5),nCode)+‘,‘ from Table1 a where a.vcName =b.vcName AND a.dtCreateTime=b.dtCreateTime for xml path(‘‘)),‘‘)AS vcCode FROM Table1 b --分隔符在后,对于拼接名称的,个人觉得用substring、left还麻烦点,不如在后台或者前台去处理
sql 针对多个id或名称的分割和组合
标签: