I'm trying to query the iSeries DB2 v6r1m0. I'd like to borrow answers from Concatenate many rows into a single text string?
DECLARE @Names VARCHAR(8000)
SELECT @Names = COALESCE(@Names + ', ', '') + Name
FROM People
WHERE Name IS NOT NULL
I have attempted to apply it to the query below, but failed. I'm trying to concatenate the comments.
ATOMIC throws an error. It was taken from one answer somewhere. @comments and comments do not work. Section is a valid token. Not sure what that means.
BEGIN ATOMIC
DECLARE @comments varchar(100)
SELECT
mh.ID
,mh.OtherStuff
,me.ID
,@Comments = COALESCE(@Comments + '<br />' ,") + me.Comment
FROM
/*insertTblName*/ mh
INNER JOIN
/*insertTblName*/ me
ON
me.ID = mh.ID
WHERE
me.ID = @parameter
END
I'm trying to accomplish this.
ID Comment 0 Hello 0 World 1 Foo 1 Bar
To....
ID Comment 0 Hello World 1 Foo Bar
I usually test my SQL statements in System i Navigator before using them in ADO.Net.
Try with this example and data to understand the process and let me know if you solve it.
This is the result.