Unix Technical Forum

Informix 4gl Query

This is a discussion on Informix 4gl Query within the Informix forums, part of the Database Server Software category; --> Whilst I have a MS SQL background, I need assistance with the following please:- I have a table with ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 07:38 AM
Gary Cobden
 
Posts: n/a
Default Informix 4gl Query

Whilst I have a MS SQL background, I need assistance with the
following please:-

I have a table with the following structure:-
customer_id; text_line_number; text_info

Each customer_id can have several records, each with a different
text_line_number

I need to consolidate all the records in a new table so that there is
one record for each customer_id and the text_info fields are
consolidated
eg:-
customer_id 7777;
text_line_number 1;
text_info abc;

customer_id 7777;
text_line_number 2;
text_info def;

becomes - in the consolidated record
customer_id 7777;
text_info abc def;

Any assistance would be appreciated

Thanks

Gary
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 07:38 AM
Doug Lawry
 
Posts: n/a
Default Re: Informix 4gl Query

Gary,

The following SQL (or similar 4GL) should do it:

CREATE PROCEDURE consolidate_text()

DEFINE last_id INTEGER;
DEFINE this_id INTEGER;
DEFINE line_no INTEGER;
DEFINE old_text VARCHAR(255);
DEFINE new_text VARCHAR(255);

LET last_id = NULL;
LET new_text = NULL;

FOREACH

SELECT customer_id, text_line_number, TRIM(text_info)
INTO this_id, line_no, old_text
FROM old_table
WHERE LENGTH(TRIM(text_info)) > 0
ORDER BY 1, 2

IF this_id != last_id THEN
INSERT INTO new_table VALUES (last_id, new_text);
LET new_text = NULL;
END IF

IF new_text IS NULL THEN
LET new_text = old_text;
ELSE
LET new_text = new_text || ' ' || old_text;
END IF

LET last_id = this_id;

END FOREACH

IF last_id IS NOT NULL THEN
INSERT INTO new_table VALUES (last_id, new_text);
END IF

END PROCEDURE;

EXECUTE PROCEDURE consolidate_text();

Use LVARCHAR if you are using version 9 and need more than 255 bytes.

--
Regards,
Doug Lawry
www.douglawry.webhop.org


"Gary Cobden" <gary.cobden@nhs.net> wrote in message
news:4a40e4ac.0409100657.1ca9a1d6@posting.google.c om...
> Whilst I have a MS SQL background, I need assistance with the
> following please:-
>
> I have a table with the following structure:-
> customer_id; text_line_number; text_info
>
> Each customer_id can have several records, each with a different
> text_line_number
>
> I need to consolidate all the records in a new table so that there is
> one record for each customer_id and the text_info fields are
> consolidated
> eg:-
> customer_id 7777;
> text_line_number 1;
> text_info abc;
>
> customer_id 7777;
> text_line_number 2;
> text_info def;
>
> becomes - in the consolidated record
> customer_id 7777;
> text_info abc def;
>
> Any assistance would be appreciated
>
> Thanks
>
> Gary



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:30 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com