I have the following query which returns more than 1 result (max is about 10rows not more!), how can I return all results as a single string?
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))
Have tried using STUFF
as follows but its not working:
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)))