Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:23:01+00:00 2026-05-27T06:23:01+00:00

I’m extracting data from various sources into one table. In this new table, there’s

  • 0

I’m extracting data from various sources into one table. In this new table, there’s a field called lineno. This field value is should be in sequence based on company code and batch number. I’ve wrote the following procedure

CREATE PROCEDURE update_line(company CHAR(4), batch CHAR(8), rcptid CHAR(12));

DEFINE lineno INT;

SELECT Count(*) 
INTO lineno
FROM tmp_cb_rcpthdr
WHERE cbrh_company = company
AND cbrh_batchid = batch;

UPDATE tmp_cb_rcpthdr
SET cbrh_lineno = lineno + 1
WHERE cbrh_company = company
AND cbrh_batchid = batch
AND cbrh_rcptid = rcptid;

END PROCEDURE;

This procedure will be called using the following trigger

CREATE TRIGGER tmp_cb_rcpthdr_ins INSERT ON tmp_cb_rcpthdr 
REFERENCING NEW AS n
FOR EACH ROW
(
    EXECUTE PROCEDURE update_line(n.company, cbrh_batchid, cbrh_rcptid)
);

However, I got the following error

SQL Error = -747 Table or column matches object referenced in
triggering statement.

From oninit.com, I learn that the error caused by a triggered SQL statement acts on the triggering table which in this case is the UPDATE statement.
So my question is, how do I solve this problem? Is there any work around or better solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:23:02+00:00Added an answer on May 27, 2026 at 6:23 am

    I think the design needs to be reconsidered. For a start, what happens if some rows get deleted from tmp_cb_rcpthdr ? The COUNT(*) query will result in duplicate lineno values.

    Even if this is an ETL only process, and you can be confident the data won’t be manipulated from elsewhere, performance will be an issue, and will only get worse the more data you have for any one combination of company and batch_id.

    Is it necessary for the lineno to increment from zero, or is it just to maintain the original load order? Because if it’s the latter, a SEQUENCE or a SERIAL field on the table will achieve the same end, and be a lot more efficient.

    If you must generate lineno in this way, I would suggest you create a second control table, keyed on company and batch_id, that tracks the current lineno value, ie: (untested)

    CREATE PROCEDURE update_line(company CHAR(4), batch CHAR(8));
    
        DEFINE lineno INT;
    
        SELECT cbrh_lineno INTO lineno 
        FROM linenoctl
        WHERE cbrh_company = company
        AND cbrh_batchid = batch;
    
        UPDATE linenoctl
        SET cbrh_lineno = lineno + 1
        WHERE cbrh_company = company
        AND cbrh_batchid = batch;
        -- A test that no other process has grabbed this record
        -- might need to be considered here, ie cbrh_lineno = lineno
    
        RETURN lineno + 1
    END PROCEDURE;
    

    Then use it as follows:

    CREATE TRIGGER tmp_cb_rcpthdr_ins INSERT ON tmp_cb_rcpthdr 
    REFERENCING NEW AS n
    FOR EACH ROW
    (
        EXECUTE PROCEDURE update_line(n.company, cbrh_batchid) INTO cbrh_lineno
    );
    

    See the IDS documentation for more on using calculated values with triggers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.