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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:15:05+00:00 2026-05-13T07:15:05+00:00

This might be a doozy of a question or I might be asking too

  • 0

This might be a doozy of a question or I might be asking too much at once:

In a Nutshell
How can I SELECT rows from a table between two occurrences of “description like ‘B/O INFO %’ or between ‘B/O INFO %’ and the last row of a given order number (WHERE OrderNo = 12345678)

Background
I am attempting to put together an open order line item report for a client of our business. The database I’m working with old, but “tried and true” and its design and the processes that write to it should be considered immutable for the purposes of answering this question (primarily because the processes that write data to this table are difficult to deal with {COBOL on a Unisys mainframe, mainframe to MSSQL replication, no fully qualified Unisys mainframe COBOL programmer available, migrating off the mainframe, etc.}).

What I’ve been trying to accomplish for 2 weeks now is to create a SELECT statement that returns a hierarchy of orders and order line items. This hierarchy represents an order placed by our client(s) and all the spawned “child” orders attempting to fill (wholly or partially) line items from the “root” order.

When an order is placed many automated and manual processes are applied to it. If the system sees an order line item can be wholly fulfilled by shipping from a different warehouse, it’ll create a new child order for those line items. If a line item quantity is unavailable, it’ll partially ship and create a backorder for the remainder. If the client really needs the line item, a human will manually create a new order sourcing the part from a different location.

Problem
The frustrating situation is a non-indexed char(21) column is used to declare what line items in child orders apply to a given parent order and that that linking information is not on the same line as the actual product ordered – it’s a completely separate “comment” line. What I’m having real trouble with is trying to SELECT specific order line items from these child orders. The most troublesome being SELECTing order line items between two instances of a matching description pattern or the end of the order lines.

I’ve tried all manner of JOINs and WHEREs etc. I’m no DBA, but I’m well above the level “knows enough to be dangerous” and I’ve come to the end of my understanding trying to get this together.

What I Need/Want to Do
Create a stored procedure that returns a result set of all order numbers and their respective item numbers in the order hierarchy I can then use to determine quantity fulfillment of the root order’s line items.

Details
The way these comment lines in child orders relate to their parents is as follows:

  1. A description starting with “@???/” means a child order (see #2 below) has been created with the order number matching the digits between slashes.
  2. A description starting with “MEO INFO” means all the items in the order (see #1 above) are related to the order matching the numeric portion of the description.
  3. A description starting with “*S/” means a child order has been created (see #4 below) with the order number matching the digits between slashes.
  4. A description starting with “B/O #” means the line above is relevant to the order matching the numeric portion of the description. (see #3 above)
  5. A description starting with “B/O INFO” means at least one line below until the next occurrence of “B/O INFO” or the end of the order line items is relevant to the order matching the numeric portion of the description. The parent will not have a reference to this child order.
  • Orders containing line comments like “B/O  #” or “B/O INFO” can be “composite” child orders fulfilling order line items from one or more parent orders. Associated line items as detailed in the above list.
  • Finding “@???/” and “*S/” lines in an order are easy references to child orders.

With this sample data, the root order number is 12345678 and I need to build a hierarchy of all related child line items.
Sample Data

OrderNo |ItemNo |Description   |LineCD
-------------------------------------------------
Lines pointing to child orders
12345678 1  @LVL/11223344/001
12345678 2  *S/11335577/12345ELEM

All lines relevant to parent order
11223344 1  MEO INFO 12345678
11223344 2  RAIL
11223344 3  BODY OVEN WELD ASM

Comment lines indicate above line is for a parent order
55667788 1  PUMP&MOTOR
55667788 2  B/O #  12345678      
55667788 3  *S/22446688/12345GLAS
55667788 4  B/O #  77553311 //The above line is NOT related to 12345678

Comment lines indicating line(s) below until end of lines or
next comment are for a parent order
98765432 31  B/O INFO 12345678  C
98765432 32  CNTRL-ELEC
98765432 33  STRIKE
98765432 34  CONTROL-ELECTRICAL
98765432 35  B/O INFO 88664422  C

I hope this question is answerable. If not, it’ll at least give your brain a good work-out.

  • 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-13T07:15:06+00:00Added an answer on May 13, 2026 at 7:15 am

    Wow, what a mess.

    Although I hate recommending the use of cursors, I don’t see any other way to get the data you want. I don’t think standard set based operations (selects with joins etc) are going to pull the data in any reasonable matter.

    Which leaves us with 3 potential solutions.

    One, do the processing in your code. This has many obvious drawbacks depending on the size of your data set.

    Two, do the processing using cursors. Cursors are not very performant, but with your data structured that way performance isn’t even on the radar.

    Three, use some type of CLR based solution. The drawbacks here are your ability to install it and whether your sql server supports that.

    Good luck.

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

Sidebar

Related Questions

This might be a simple question but I've searched and searched and can't find
This might be a very basic question but it confuses me. Can two different
This might be a very simple question, but more or less, I'm asking to
This might be a silly question, but I can't seem to find a solution...
This might sound like an odd question but how can on define a generic
This might be a very basic question but I can't find the correct command
This might be a simple question, but can ESX handle multiple File Manager instances
this might be a simple question but when creating a database can you instead
This might be a ridiculous question but I can't find it asked yet here
This might seem like a very easy question for some of you folks, but

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.