Introduction
This blog describes how to get Comma Separated data from the table. Content will be added soon. If you are familiar with this, please consider adding any troubleshooting tips that may help the community.
Created one example table
- CREATE TABLE Articles
- (
- Title VARCHAR(50),
- ArticleType VARCHAR(10),
- Tags VARCHAR(500)
- )
Insert data in table
- insert into Articles values('test article title-01','C','C')
- insert into Articles values('test article title-01','C','C++')
Created function to take Events with Comma Separated on Event Type basis
- CREATE FUNCTION dbo.MakeCommaValue (@pC2 AS VARCHAR(10))
- RETURNS VARCHAR(8000)
- AS
- BEGIN
- DECLARE @oResult VARCHAR(8000)
- SELECT @oResult= COALESCE(@oResult+',','')+CAST(Events AS VARCHAR(10))
- FROM Articles WITH (NOLOCK)
- WHERE ArticleType = @pC2
- ORDER BY Tags
- RETURN @oResult
- END
-
- SELECT DISTINCT Title,ArticleType,dbo.MakeCommaValue('B') as 'Tags' FROM Articles
Result
Title | ArticleType | Tags |
test article title-01 | c | C, C++ |