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 8989251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:12:40+00:00 2026-06-15T22:12:40+00:00

I have data that is organized as follows: Invoice_Id Invoice_Line Kit_Flag Part_Number ———- ————

  • 0

I have data that is organized as follows:

Invoice_Id  Invoice_Line  Kit_Flag  Part_Number
----------  ------------  --------  -----------
AB12345               1    K        KT-1234A
AB12345               2    C        1234567
AB12345               3    C        1234568
AB12345               4    C        1234569
AB12345               5    C        1234560
AB12345               6    K        KT-1234C
AB12345               7    C        1234561
AB12345               8    C        1234562
AB12345               9    K        KT-1234Q
AB12345              10    C        5678901
AB12345              11    C        1234561
AB12345              12    C        1234562

I am attempting to get the Part_Number value for subsequent lines from the last line where the Kit_Flag was a ‘K,’ within a single Invoice_Id (K = Parent, C = Child). I only listed one invoice ID here for simplicity.

So, for the data above, the results would look like this:

Invoice_Id  Invoice_Line  Kit_Flag  Part_Number Parent_Part
----------  ------------  --------  ----------- ------------
AB12345               1    K        KT-1234A    KT-1234A
AB12345               2    C        1234567     KT-1234A
AB12345               3    C        1234568     KT-1234A
AB12345               4    C        1234569     KT-1234A
AB12345               5    C        1234560     KT-1234A
AB12345               6    K        KT-1234C    KT-1234C
AB12345               7    C        1234561     KT-1234C
AB12345               8    C        1234562     KT-1234C
AB12345               9    K        KT-1234Q    KT-1234Q
AB12345              10    C        5678901     KT-1234Q
AB12345              11    C        1234561     KT-1234Q
AB12345              12    C        1234562     KT-1234Q

In Excel, this is possible by something like “=If(C2=”K”,C3,D2),” and that’s actually what we had to settle with for the time being, but I am trying to automate this.

The table is on both Oracle 9i and Sybase, but the Sybase instance does not have analytic functions.

I didn’t think this would work (and it didn’t), but notionally it shows what I am trying to do:

select
  t.Invoice_Id, t.Invoice_Line, t.Kit_Flag, t.Part_Number,
  case
    when Kit_Flag = 'K' then Part_Number
    else lag(Parent_Part, 1) over (partition by Invoice_Id order by Invoice_Line)
  end as Parent_Part
from Invoice_Data t

Any advice and/or guidance is welcome.

  • 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-15T22:12:42+00:00Added an answer on June 15, 2026 at 10:12 pm

    One way to do this is with nested ranking functions. First, assign a constant value to everything that gets one value (using max() over) and then use this as a partition.

    select t.Invoice_Id, t.Invoice_Line, t.Kit_Flag, t.Part_Number,
           max(KitPart) over (partition by invoice_id, KitNum) as Parent_Part
    from (select t.*,
                 sum(isKit) over (partition by InvoiceId order by InvoiceLine) as KitNum
          from (select t.Invoice_Id, t.Invoice_Line, t.Kit_Flag, t.Part_Number,
                       (case when Kit_Flag = 'K' then 1 else 0 end) as IsKit,
                       (case when Kit_Flag = 'K' then Part_Number end) as KitPart
                from Invoice_Data t
               ) t
         ) t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data that is organized in kind of a key-key format, rather than
I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
I have data that is organized in panels like this (see below for output
I have a lot of tab delimited data that is organized into multiple rows
I have a file that is organized into columns, with data that needs to
I have my UITableView data organized such that the sections of the table are
I have a set of data that's organized hierarchically that should be able to
I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study:
I have data that I would like to compute some statistics with. The data
For an XML file I am creating I have data that contains a bullet

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.