标签:style color os io 使用 strong ar for 数据
CREATE ASSEMBLY [SqlStrConcate] AUTHORIZATION [dbo] FROM ‘D:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Binn/SqlStrConcate.dll‘ WITH PERMISSION_SET = SAFE GO上面的代码中, <sql安装根目录>为D:/Program Files/Microsoft SQL Server/
CREATE AGGREGATE StrConcate (@input nvarchar(200)) RETURNS nvarchar(max) EXTERNAL NAME SqlStrConcate.Concatenate
-------------------------------------------------------------- -- 创建测试表 -------------------------------------------------------------- create table test_tb(pk_val int, startdate varchar(10), enddate VARCHAR(10), corpname VARCHAR(20)) -------------------------------------------------------------- -- 插入测试数据 -------------------------------------------------------------- insert into test_tb select 1, ‘2005-01-01‘, ‘2007-06-29‘, ‘方正科技‘ union all select 1, ‘2007-07-01‘, ‘2009-06-29‘, ‘清华紫光‘ union all select 1, ‘2009-01-01‘, null, ‘用友软件‘ union all select 2, ‘1995-01-01‘, ‘2003-06-29‘, ‘微软中国‘ union all select 2, ‘2004-07-01‘, ‘2009-06-29‘, ‘盛大网络‘ go -------------------------------------------------------------- -- 查询测试 -------------------------------------------------------------- select pk_val, dbo.StrConcate(startdate + ‘~‘ + isnull(enddate, ‘至今‘) + ‘:‘ + corpname) lvl_str from test_tb group by pk_val -------------------------------------------------------------- -- 查询结果 -------------------------------------------------------------- pk_val lvl_str ----------- ----------------------------------------------------------------------------------------- 1 2005-01-01~2007-06-29:方正科技,2007-07-01~2009-06-29:清华紫光,2009-01-01~至今:用友软件 2 1995-01-01~2003-06-29:微软中国,2004-07-01~2009-06-29:盛大网络
标签:style color os io 使用 strong ar for 数据
原文地址:http://www.cnblogs.com/lzmch/p/3948927.html