我有以下查询返回超过 1 个结果(最多大约 10 行而不是更多!),如何将所有结果作为单个字符串返回?
SELECT DISTINCT(e.Username)
FROM TblLeaveEmployee l
JOIN TblLeaveApprovalsBy a on l.EmployeeId = a.UserID
JOIN TblEmployee e on l.EmployeeId = e.id
where l.EmployeeId IN
(select UserID
FROM TblLeaveApprovalsBy
WHERE ApprovalUserID IN
(SELECT ApprovalUserID from TblLeaveApprovalsBy where UserID = 77))
已尝试使用STUFF
如下但它不起作用:
DECLARE @CodeNameString varchar(100)
SELECT
@CodeNameString = STUFF(
SELECT DISTINCT(e.Username)
FROM TblLeaveEmployee l
JOIN TblLeaveApprovalsBy a on l.EmployeeId = a.UserID
JOIN TblEmployee e on l.EmployeeId = e.id
where l.EmployeeId IN
(select UserID
FROM TblLeaveApprovalsBy
WHERE ApprovalUserID IN
(SELECT ApprovalUserID from TblLeaveApprovalsBy where UserID = 77)))