我有一个表“任务”,可以分配多个用户,存储在表“分配”中。
我有 q COALESCE 查询将我的用户分组为一个字符串:
DECLARE @Names VARCHAR(8000)
SELECT @Names = COALESCE(@Names, '') + taskAssignment.FullName + '; '
FROM dbo.v_TaskAssignment taskAssignment
WHERE (taskAssignment.TaskId = @TaskId)
AND taskAssignment.AssignmentIsRemoved = 'False'
AND taskAssignment.FullName IS NOT NULL
SELECT @Names as Names
我对任务的查询:
SELECT Id, Summary
FROM dbo.v_Task
我希望我的任务查询有一个字符串列,其中列出了用分号分隔的所有用户。但是,这似乎不起作用:
DECLARE @Names VARCHAR(8000)
SELECT
dbo.v_Task.Id, dbo.v_Task.Summary,
(SELECT @Names = COALESCE(@Names, '') + taskAssignment.FullName + ';'
FROM dbo.v_TaskAssignment taskAssignment
WHERE (taskAssignment.TaskId = dbo.v_Task.Id)
AND taskAssignment.AssignmentIsRemoved = 'False'
AND taskAssignment.FullName IS NOT NULL
SELECT @Names as Names) AS Assignements
FROM
dbo.v_Task
INNER JOIN
dbo.v_TaskAssignment ON dbo.v_Task.Id = dbo.v_TaskAssignment.TaskId
我收到以下错误:
消息 102,级别 15,状态 1,第 3 行
'=' 附近的语法不正确。
消息 102,级别 15,状态 1,第 8 行
')' 附近的语法不正确。
如何在任务选择查询中获取 Coalesce 查询?