Sql 줄 전환 STUFF



  SELECT  DISTINCT BizID
  ,STUFF(
  (
    SELECT ',' + ApproveName
    FROM T_Common_ApproveNode
            
    WHERE BizID = A.BizID
    FOR XML PATH('')
  )
  ,1
  ,1
  ,''
 ) AS ApproveNameStr
FROM T_Common_ApproveNode AS A

BizID                           | ApproveNameStr
000835d70a99447f96b21d4b827c45d8|  ,  ,  ,   ,  ,  4,  ,  
0010f69ef6f04d0ab0118ebd336c5454|  ,   1,   ,   ,  1,   
001ca702982a4311bd4dd8278738a310|  ,   ,   ,   ,  4,   ,   ,   
0010f69ef6f04d0ab0118ebd336c5454|  ,   1,   ,   ,  1,   







--  JSON    
SELECT  TOP 10 InvoiceCategory,InvoiceType FROM T_BILL_INVOICE
FOR JSON PATH('')




--  XML
SELECT  TOP 10 InvoiceCategory,InvoiceType FROM T_BILL_INVOICE
FOR XML PATH('')





 
SELECT ''''+ CAST( AA.ProgramID AS VARCHAR(1000) )   +''','
 FROM (
 select * from (
 select a.ProgramID,
 (select top 1 c.ParentProgramID from Sys_ProgramList c where a.ParentProgramID=c.ProgramID) ParentProgramID
 from Sys_ProgramList a inner join Sys_PageMain b on a.ProgramID=b.ProgramID
 where ISNULL(a.IsShow,0)=1 and isnull(a.IsBillPage,0)=1 and b.ListProgramID<>b.ProgramID) BillMain 
 where isnull(ParentProgramID,0)<>0
) AS AA
FOR XML PATH('')


    select  STUFF((
    SELECT 
      '{"businessCode":'+ cast(billno as varchar(20)) +'"'
      + ',"operatorCode":'+(select  cUserCode from Sys_User WHERE  iUserID =  Bywho)+'"'
      +',"auditStatus":PASS"'+'"'
      +',"approvalTxt":    "'+'"'
      + ',"auditDate":'+ CONVERT(varchar(100), endtime, 21) +'"'
      +'}'
      FROM  DJLXSZ60_log  WHERE  node = 18 and nodestatus = 5 and  endtime > '2019-4-24'   order by endtime desc 
      for xml path(''), type
    ).value('.', 'varchar(max)'), 1, 1, '')  



다음으로 전송:https://www.cnblogs.com/imtudou/p/11251848.html

좋은 웹페이지 즐겨찾기