ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Trigger a subprocedure on each inserted row

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trigger a subprocedure on each inserted row

    Hi all.
    I've been using embedded SQL for a long time, but I have always wondered if it's possible to perform a single insert statement - based on a select statement, not on values - and have a subprocedure triggered for each row (basically to print something about the row just written).
    I know maybe I shoud use select from final table, but if there was a simpler way would be much better.
    Thanks.

  • #2
    May be I have misunderstood the question, but...

    Code:
    INSERT INTO TABLEA (COLUMNS)
    SELECT (COLUMNS) FROM TABLEB WHERE CONDITIONS
    You don't need to indicate the columns at the target table if the SELECT returns all clumns expected at target table (TABLEA).

    Comment


    • #3
      Originally posted by inigo.redin View Post
      May be I have misunderstood the question, but...

      Code:
      INSERT INTO TABLEA (COLUMNS)
      SELECT (COLUMNS) FROM TABLEB WHERE CONDITIONS
      You don't need to indicate the columns at the target table if the SELECT returns all clumns expected at target table (TABLEA).
      Thanks but yes, this is not what I meant.
      To be more clear: let's say I'm doing an SQL insert like you said, into a sqlrpgle program. I would like a custom subprocedure (possibly in the same program) to be executed after each insert.
      I don't think it's possible but... just asking.

      Comment


      • #4
        Two possibilities spring to mind.

        1) Always do the inserts via a subprocedure and invoke the additional processing that way or

        2) (The real answer) put an insert trigger on the table and have the trigger fire the additional logic.

        Comment

        Working...
        X