日期:2014-05-17 浏览次数:20639 次
MERGE INTO [GROUP_MEMBER] AS A
USING @MEMBER_TABLE AS B
ON (A.[CUSTOMER_ID]=B.[CUSTOMER_ID] AND A.[GROUP_ID]=@GROUP_ID)
WHEN NOT MATCHED
THEN INSERT([CUSTOMER_ID],[GROUP_ID]) VALUES(B.[CUSTOMER_ID],@GROUP_ID)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
/*
工单号 操作者
a1 张三
a1 王二
a1 李四
现在要得到查询结果:
工单号 操作者
a1 张三、王二、李四
*/
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[test1]') AND type in (N'U'))
DROP TABLE [dbo].[test1]
GO
CREATE TABLE [dbo].[test1](
工单号 [varchar](10) NOT NULL,
操作者 [varchar](10) NOT NULL
) ON [PRIMARY]
GO
INSERT [test1]
VALUES ('a1','张三'),('a1','王二'),('a1','李四')
select 工单号,
操作者=stuff((select '、'+操作者
from test1