Re: Sql to concatenate multiple rows to a single row / column
- From: "scottishpoet" <dryburghj@xxxxxxxxx>
- Date: 10 Nov 2005 10:13:11 -0800
This should do the sort of thing you want, the only caviat is the
function will run for every row returned by the calling select.
If I wrote it ia proper programming language I'd probably do it
differently.
CREATE FUNCTION cat_parts(p_num INTEGER) RETURNING CHAR(255);
DEFINE tmp_str, ret_str, ret_val CHAR(255);
LET ret_Str = "Allergies";
LET ret_val = "";
FOREACH SELECT allergy INTO ret_val FROM allergy
WHERE patid = p_num
AND allergy IS NOT NULL
LET tmp_str = ret_str;
LET ret_str = TRIM(tmp_str) ||" ; " || TRIM(ret_val);
END FOREACH
RETURN ret_str;
END FUNCTION;
SELECT patid, patnum , cat_parts(patid) FROM patient;
.
- Follow-Ups:
- References:
- Prev by Date: Re: Error 1829 from a Webservice
- Next by Date: Re: UK IUG Meeting
- Previous by thread: Sql to concatenate multiple rows to a single row / column
- Next by thread: Re: Sql to concatenate multiple rows to a single row / column
- Index(es):
Relevant Pages
|