数据范例如下: 要得到的结果目标,获取type相同的所有names拼接在一起的字符串: SqlServer并没有一个直接拼接字符串的函数,下面所提到的方法,只是日常的开发中自己个人用到的一些思路,仅供参考! )) 创建表变量,字段为你需要返回的各列的值 insert @tempTable select [type],MAX([name]) name from test group by [type] 插入初始的聚合数据 updateTag: update @tempTable set [name
--查询所有数据select A.*,B.* from(select z.id,z.requestId,z.FBillNo,dt5.FCauseAndProcess,dt5.FEquipmentNo,dt2.FDetail,row_number() over (PARTITION BY z.id ORDER BY z.id) RNfrom formtable z left join formtable2 dt2 on dt2.mainid=z.idleft join formtable5 dt5
SELECT B.id , LEFT(tempname, LEN(tempname) - 1) AS name FROM ( SELECT id , ( SELECT name + ',' FROM tablename WHERE id = A.id FOR XML PATH('') ) AS tempname FROM tablename A GROUP BY id ) B
1 exec sp_executesql N'SELECT 2 [Extent2].[Id] AS [Id], 3 [Extent2].[Name] AS [Name], 4 [Extent2].[Description] AS [Description], 5 [Extent2].[RoleTypeNum] AS [RoleTypeNum], 6 [Extent2].[IsDeleted] AS [IsDeleted], 7 [Extent2].[AddDate] AS [AddDate],
DECLARE @var VARCHAR(50) SET @var ='116.404556|39.915156' 方式一: SELECT CASE WHEN ISNULL(@var,'') <> '' THEN LEFT(@var,CHARINDEX('|',@var)-1) ELSE '' END Longitude ,CASE WHEN ISNULL(@var,'') <> '' THEN RIGHT(@var,CHARINDEX('|',@var)-2) ELSE '' E