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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:18:19+00:00 2026-05-25T03:18:19+00:00

I wish to split an order to generate multiple work orders depending on the

  • 0

I wish to split an order to generate multiple work orders depending on the Optimum Lot Quantity (OLQ) meaning the sum the quantity in a work order would not exceed the OLQ.

Here is my order Table sample data:

Order   Item    Product Qty
OR-01   I-001   PRD-01  70
OR-01   I-001   PRD-02  15
OR-01   I-001   PRD-03  55

The OLQ for this order is 30 and therefore the sum of the qty of work order should not exceed 30. But the work order can has multiple products of the same item (item is the parent for product).
Here is how I wish to split this order to create work orders on the basis of OLQ:

Order   WorkOrd Seq Item    Product Qty
OR-01   WO-0001 001 I-001   PRD-01  30
OR-01   WO-0002 001 I-001   PRD-01  30
OR-01   WO-0003 001 I-001   PRD-01  10
OR-01   WO-0003 002 I-001   PRD-02  15
OR-01   WO-0003 003 I-001   PRD-03  5
OR-01   WO-0004 001 I-001   PRD-03  30
OR-01   WO-0005 001 I-001   PRD-03  20

Note that WO-0003 has three products with 10, 15 and 5 amounting to 30. Also note that the last Work order WO-0005 has only 20 qty (which is the remaining).

In the attachment I have highlighted the work orders in different colors for easy understanding.Order to Work Order conversion

Kindly help me to achieve this.

Thanks in advance.

  • 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-25T03:18:19+00:00Added an answer on May 25, 2026 at 3:18 am

    I dont like working with cursors, but sometimes they are handy.

    Here you go:

    -- Test data
    declare @orders table 
        (Order_a varchar(20),
         Item varchar(20),
         Product varchar(20),
         Qty int)
    
    insert into @orders
    select 'OR-01',   'I-001',   'PRD-01',  70
    union all
    select 'OR-01',   'I-001',   'PRD-02',  15
    union all
    select 'OR-01',   'I-001',   'PRD-03',  55
    
    -- End test data
    
    declare @workorders table 
        (Order_a varchar(20),
         WorkOrd varchar(20),
         Seq int,
         Item varchar(20),
         Product varchar(20),
         Qty int)
    
    
    declare @olq int
    set @olq = 30
    
    declare @qty_left int
    set @qty_left = @olq
    
    declare @wo int
    set @wo = 1
    
    declare @seq int
    set @seq = 1
    
    declare @Order_a varchar(20)  
      ,@Item varchar(20)
      ,@Product varchar(20)
      ,@Qty int
    
    -- Declare and set the cursor    
    declare qtycursor cursor for    
    select Order_a  
      ,Item  
      ,Product  
      ,Qty  
    from @orders
    
    open qtycursor    
    fetch next from qtycursor into @Order_a, @Item, @Product, @Qty    
    while @@fetch_status = 0     
    begin    
    
        while @Qty <> 0
        begin
            if @Qty < @qty_left
            begin
                insert into @workorders
                select @Order_a, 'WO-'+CAST(@wo as varchar), @seq, @Item, @Product, @Qty
    
                set @seq = @seq + 1 
                set @qty_left = @qty_left - @Qty
                set @Qty = 0
            end
            else
            begin
                insert into @workorders
                select @Order_a, 'WO-'+CAST(@wo as varchar), @seq, @Item, @Product, @qty_left
    
                set @Qty = @Qty - @qty_left
                if @Qty > 0
                begin
                    set @seq = 1    
                end
                set @wo = @wo + 1
                set @qty_left = @olq
    
            end
        end
    
    
    
    
    fetch next from qtycursor into @Order_a, @Item, @Product, @Qty    
    end    
    close qtycursor    
    deallocate qtycursor    
    
    select * from @workorders
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to implement a 2d bit map class in Python. The class would
I wish to use xml and xsl to generate controls on an asp.net page.
I wish to test a function that will generate lorem ipsum text, but it
I wish to known if exist a clean way to split a string using
I wish to convert a single string with multiple delimiters into a key=>value hash
Let's say we have a long string we wish to split into strings 64
I would say my knowledge in C is fair, and I wish to extend
Hi I am having string called 'santhosh'. I wish to split this text as
I wish to split text into sentences. Can anyone help me? I also need
I wish Subversion had a better way of moving tags. The only way that

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.