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

  • SEARCH
  • Home
  • 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 8092377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:16:15+00:00 2026-06-05T20:16:15+00:00

I’m writing this query and I’m running into a mental road block. I keep

  • 0

I’m writing this query and I’m running into a mental road block. I keep looping around myself and it’s frustrating.

Here’s the tables:

PO_HEADER(IC_PO_HEADER Unique)

IC_PO_HEADER  |  po_number | revision_number
123              p123              0
456              p123              2         
789              p123              48

PO_LINE(IC_LINE_KEY & IC_PO_LINE Unique)

IC_PO_HEADER  | po_number  | line_rev_no  | ic_line_key  |  ic_po_line
123             p123               0        8246321         214578
123             p123               0        8246322         214579
123             p123               0        8246322         214580

There are roughly 150 tables on each column, but these are the only ones that actually matter, as that’s what everything is checking against, and I want to copy the entire line to display like this:

IC_PO_HEADER  | po_number  | line_rev_no  | ic_line_key  |  ic_po_line
123             p123               0        8246321         214578
123             p123               0        8246322         214579
123             p123               0        8246323         214580
456             p123               2        8246324         214581
456             p123               2        8246325         214582
456             p123               2        8246326         214583
789             p123               48       8246327         214584
789             p123               48       8246328         214585
789             p123               48       8246329         214586

I was going to use an insert with selected nests but I keep running myself in a circle. This is sample data, there are somewhere in the order of 15,000 records in PO_HEADER and currently 40,000 in PO_LINE.

Pseudo-codey:

If PO_HEADER.ic_po_header does not exist in PO_LINE.ic_po_header AND
PO_HEADER.po_number does exist in PO_LINE.po_number
COPY PO_LINE.* where the above is true AND 
    SET PO_LINE.line_rev_no to PO_HEADER.revision_number (do this until no more PO_HEADER.revision_number's exist that do not meet the criteria)
    AUTONUMBER/INCREMENT PO_LINE.ic_line_key AND PO_LINE.ic_po_line
  • 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-06-05T20:16:16+00:00Added an answer on June 5, 2026 at 8:16 pm

    The following will produce the output you specified.

    WITH cte 
         AS (SELECT ph.IC_PO_HEADER, 
                    ph.PO_NUMBER, 
                    ph.revision_number, 
                    pl.ic_line_key, 
                    pl.ic_po_line, 
                    Row_number() 
                      OVER ( 
    
                        ORDER BY ph.IC_PO_HEADER, IC_LINE_KEY) Rn 
             FROM   PO_HEADER ph 
                    INNER JOIN PO_LINE pl 
                            ON ph.po_number = pl.po_number 
             ) 
    SELECT t1.IC_PO_HEADER, 
           t1.PO_NUMBER, 
           t1.revision_number, 
           t1.ic_line_key,
           t2.ic_line_key + t1.rn - 1, 
           t2.IC_PO_LINE + t1.rn - 1
    FROM   cte t1
           INNER JOIN cte t2 
           ON t2.rn = 1
    
    ORDER  BY IC_PO_HEADER
    

    Using the ROW_NUMBER you can generate an AUTONUMBER. By self joining to CTE we can find the initial values for IC_LINE_KEY and IC_PO_LINE (t2.rn = 1)

    DEMO

    • 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
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 have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.