使用 SQL的 for xml path来进行字符串拼接 (group by)

参考:

http://www.cnblogs.com/repository/archive/2011/01/18/1938418.html

 

select convert(varchar(10),c.[STARTSPECDAY],120),

   (select [LeaveName]+' ' 
      from 
      (
        select convert(varchar(10),a.[STARTSPECDAY],120) STARTSPECDAY,a.[LeaveName] 
        from  [test].[dbo].[View_GetSPDay]  as a

      ) as b 
     
     where convert(varchar(10),c.[STARTSPECDAY],120)=convert(varchar(10),b.[STARTSPECDAY],120) for xml path('')

   ) as course_name

    from [test].[dbo].[View_GetSPDay]  as c  
    
    group by convert(varchar(10),c.[STARTSPECDAY],120)

  

posted @ 2014-09-25 17:17  jindahao  阅读(1905)  评论(0编辑  收藏  举报