zoukankan      html  css  js  c++  java
  • 合并同列字段,即相同ID的字符串叠加 狼

     set statistics     io on  set statistics     time on   SELECT   distinct o.OrderID,f.Flight,f.DPort,f.APort,f.TakeOffTime,f.ArrivalTime,f.SubClass, f.Sequence,ISNULL(f.RecordNo,'')AS Pnr,o.FlightClass,c.ContactName, [value]=(select stuff((select ',' + PassengerName from O_Passenger p1 (nolock) where p1.orderid =  o.OrderID for xml path('')) , 1 , 1 , ''))

    FROM dbo.O_Flight f (nolock) JOIN dbo.O_Orders o (nolock) ON f.OrderID=o.OrderID JOIN dbo.O_Contact c (nolock) ON o.OrderID=c.OrderID JOIN dbo.O_Passenger p  (nolock) ON p.OrderID=o.OrderID WHERE Flight='MU5870'

    核心函数是stuff

     [value]=(select stuff((select ',' + PassengerName from O_Passenger p1 (nolock) where p1.orderid =  o.OrderID for xml path('')) , 1 , 1 , ''))

    可以自己实现数据库函数列合并核心代码如下:

    declare @S nvarchar(500)='' 
    select @S=isnull(@S,'')+isnull( FailureSource,'')+',' from OrderPayFailure 
    SELECT @S

  • 相关阅读:
    SpringBoot整合Redis缓存
    手写一个json格式化 api
    MYSQL 5.7 无法启动(Could not open error log file errno 2)
    如何获取算法运行状态
    Spring MVC
    Java设计模式
    Java设计模式
    Java设计模式
    Java设计模式
    学习myBatis
  • 原文地址:https://www.cnblogs.com/gowhy/p/2882839.html
Copyright © 2011-2022 走看看