Consider we have a table dbo.User, and we need to get all UserIDs separated by comma the apply below script:
Example:
Select Top 5 UserID From dbo.User
gives output as below
UserID
1
2
3
4
5
DECLARE @UserID VARCHAR(MAX)
SELECT @USERID = COALESCE(@USERID+',' , '') + UserID
FROM dbo.User
SELECT @USERID
This yields output as 1,2,3,4,5,....
Example:
Select Top 5 UserID From dbo.User
gives output as below
UserID
1
2
3
4
5
DECLARE @UserID VARCHAR(MAX)
SELECT @USERID = COALESCE(@USERID+',' , '') + UserID
FROM dbo.User
SELECT @USERID
This yields output as 1,2,3,4,5,....
No comments:
Post a Comment