×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Looking for a function(s) that will provide something similar to GROUP_CONCAT() or LISTAGG()

Looking for a function(s) that will provide something similar to GROUP_CONCAT() or LISTAGG()

Looking for a function(s) that will provide something similar to GROUP_CONCAT() or LISTAGG()

(OP)
Essentially I'm attempting to accomplish concatenating data in a field for records that share the same key in a particular table, as shown below.
I've seen the GROUP_CONCAT(), and LISTAGG() listed on other similar questions, and I am familiar with implementations that would solve the situation below but it seems like PervasiveSQL 13 does not have support for these functions. I am wondering if Pervasive supports anything that I could use to solve my issue.


CODE -->

id       colour

1        red
1        blue
2        green
2        red 

Either of the following solutions would be acceptable for my use case, but the first one would be more preferable.

CODE -->

id     colour

1      red, blue
2      green, red 

OR

CODE -->

id     colour1    colour2

1      red        blue
2      green      red 

RE: Looking for a function(s) that will provide something similar to GROUP_CONCAT() or LISTAGG()

I'm not aware of a single SQL statement method of pivoting the table like you want. You might be able to create a function that generates the flattened column (colour) and use that function in the select statement. You might have to do what you are wanting in code.

Something like this:

CODE

create function udfFlattenRow(IN :ID int)
returns char(500)
as 
begin
  declare :result char(500);
  declare :loopvalue char(10);
  DECLARE c1 CURSOR FOR SELECT color FROM ttGroup where id = :ID FOR READ ONLY;
  OPEN c1;
  BulkLinesLoop:
  LOOP
    FETCH NEXT FROM c1 INTO :loopvalue;
    set :result = :result + ',' + :loopvalue; 
    IF SQLSTATE = '02000' THEN
      LEAVE BulkLinesLoop;
    END IF;       
  END LOOP;
  CLOSE c1;
  return :result;
end; 
I have not tested the function so I'm not sure if it works.

Mirtheil
http://www.mirtheil.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close