码迷,mamicode.com
首页 > 数据库 > 详细

Sql 行转列 STUFF

时间:2019-07-26 18:50:55      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:pass   zid   mon   sys   value   arc   inner   select   stat   



  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, '')  


Sql 行转列 STUFF

标签:pass   zid   mon   sys   value   arc   inner   select   stat   

原文地址:https://www.cnblogs.com/imtudou/p/11251848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!