mssql的 for xml path 与 mysql中的group_concat类似MSSQL For xml Path

/****** Script for SelectTopNRows command from SSMS ******/

SELECT D_ID,[D_Name] as Name FROM [LFBMP.LDS].[dbo].[LDS.Dictionary] Where '32,33,34,35' like '%'+convert(nvarchar(10),D_ID)+'%' FOR XML PATH

SELECT [D_Name]+',' FROM [LFBMP.LDS].[dbo].[LDS.Dictionary] Where '32,33,34,35' like '%'+convert(nvarchar(10),D_ID)+'%' FOR XML PATH('row')

SELECT [D_Name]+',' FROM [LFBMP.LDS].[dbo].[LDS.Dictionary] Where '32,33,34,35' like '%'+convert(nvarchar(10),D_ID)+'%' FOR XML PATH('')

SELECT [D_Name],D_ID FROM [LFBMP.LDS].[dbo].[LDS.Dictionary] Where ',32,33,34,35,' like '%'+convert(nvarchar(10),D_ID)+'%'

 

 

 

Select CompanyID,CompanyNameCN,CompanyNameEN,CompanyTypeIDStr
,(Select group_concat(TypeNameCN SEPARATOR ',') from com_companytype where concat(',',t1.CompanyTypeIDStr,',') like CONCAT('%,',CONCAT(CompanyTypeID),',%')) as CompanyTypeIDStrName
from com_company as t1

-- 类似MSSQL For xml Path
-- Select group_concat(TypeNameCN) from com_companytype where ',1,2,3,' like CONCAT('%',CONCAT(CompanyTypeID),'%')

 

posted @ 2016-06-14 19:00  为乐而来  阅读(2820)  评论(0编辑  收藏  举报