zoukankan      html  css  js  c++  java
  • 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, '')  
    
    
    
    
  • 相关阅读:
    java集合归纳
    判断回文数
    29:四则运算计算表达式的值
    getOutString 输出弹出字符串
    两个字符串中不同元素的个数
    字符串各个字符ASCII值加5
    23:一个整数的二进制表示中有多少个1
    Java进程间通信
    转 双重检查锁定与延迟初始化
    Key-Value键值存储原理初识(NOSQL)
  • 原文地址:https://www.cnblogs.com/imtudou/p/11251848.html
Copyright © 2011-2022 走看看