miércoles, 21 de marzo de 2018

List Horizontal in iDempiere


/*********************************************************/

-- Function: coma_concat(text, text)

-- DROP FUNCTION coma_concat(text, text);

CREATE OR REPLACE FUNCTION coma_concat(
    text,
    text)
  RETURNS text AS
$BODY$
    SELECT
    CASE
        WHEN $2 IS NULL OR $2 = '' THEN '[' ||  $1 || ']'
        WHEN $1 IS NULL OR $1 = '' THEN '[' ||  $2 || ']'
        ELSE $1 || ';' ||   '[' || $2 || ']'

    END
    $BODY$
  LANGUAGE sql VOLATILE
  COST 100;

/*********************************************************/

-- Aggregate: list_horizontal(text)

-- DROP AGGREGATE list_horizontal(text);

CREATE AGGREGATE list_horizontal(text) (
  SFUNC=coma_concat,
  STYPE=text,
  INITCOND=''
);

/*********************************************************/

EXAMPLE:

SELECT  adempiere.list_horizontal(c."name") FROM adempiere.AD_Client AS c;

RESULT:

[GardenWorld];[System];[Company X]



No hay comentarios:

Publicar un comentario