|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:08 AM
Points: 113,
Visits: 299
|
|
Okay - my challenge today, is that I need to create some labels for a "Picking List" ( BOM ) - One lable per component required.
Table ONE WorksOrder ParentPart QtyToMake
Table TWO WorksOrder Component QtyPer
View will contain repeated records for ( based on QtyToMake x QtyPer ) WorksOrder ParentPart Component
So if I need to make 3 ParentParts and it requires 2 Components per Parent - then the view ( or new table ) would contain ; WorksOrer, ParentPart, Component, ( possibly counter ) - 6 times !
From this view I can then create a report and print off the records for labels.
I am choosing to create a VIEW as I need to produce a report which unfortunately would be more complicated passing a field value as the number of records to print.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 6:28 AM
Points: 1,125,
Visits: 14,511
|
|
SteveEClarke (9/27/2012) Okay - my challenge today, is that I need to create some labels for a "Picking List" ( BOM ) - One lable per component required.
Table ONE WorksOrder ParentPart QtyToMake
Table TWO WorksOrder Component QtyPer
View will contain repeated records for ( based on QtyToMake x QtyPer ) WorksOrder ParentPart Component
So if I need to make 3 ParentParts and it requires 2 Components per Parent - then the view ( or new table ) would contain ; WorksOrer, ParentPart, Component, ( possibly counter ) - 6 times !
From this view I can then create a report and print off the records for labels.
I am choosing to create a VIEW as I need to produce a report which unfortunately would be more complicated passing a field value as the number of records to print.
So what's you're question?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:08 AM
Points: 113,
Visits: 299
|
|
Sorry - the question is ;
How can I create a view inserting repeated records based on the calculation of two fields;
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 6:28 AM
Points: 1,125,
Visits: 14,511
|
|
SteveEClarke (9/27/2012) Okay - my challenge today, is that I need to create some labels for a "Picking List" ( BOM ) - One lable per component required.
Table ONE WorksOrder ParentPart QtyToMake
Table TWO WorksOrder Component QtyPer
Also I think your table definition is not ideal. I'm assuming each "Part" is made using 1 or more "Components" and there's potential for each "Component" type to be used in more than one "Part". In which case I'd have four tables.
Table ONE WorksOrder ParentPartId QtyToMake
Table TWO ParentPartId ParentPart
Table THREE ParentPartId CompentID QtyPer
Table FOUR CompentID Component
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 6:28 AM
Points: 1,125,
Visits: 14,511
|
|
SteveEClarke (9/27/2012) Sorry - the question is ;
How can I create a view inserting repeated records based on the calculation of two fields;
If you use my suggestion, you could remove QtrPer from TABLE ONE and THREE and just insert x rows per Part/Component and the JOIN will do the work for you.
MysteryJimbo (9/27/2012)
Also I think your table definition is not ideal. I'm assuming each "Part" is made using 1 or more "Components" and there's potential for each "Component" type to be used in more than one "Part". In which case I'd have four tables.
Table ONE WorksOrder ParentPartId QtyToMake
Table TWO ParentPartId ParentPart
Table THREE ParentPartId CompentID QtyPer
Table FOUR CompentID Component
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:08 AM
Points: 113,
Visits: 299
|
|
Unfortunately the tables are already defined in our ERP system -
we have - WIPMaster and WIPMaterials
The Master is the header and contains WOrksOrder, Parent and Qty2Make The Materials contains the WorksOrder, Compoents and QtyPer
|
|
|
|
|
UDP Broadcaster
      
Group: General Forum Members
Last Login: Yesterday @ 11:04 PM
Points: 1,456,
Visits: 14,263
|
|
something along these lines......??
--=== this relies on a "numbers" or "tally" table --=== http://www.sqlservercentral.com/articles/T-SQL/62867/ by Jeff Moden
; WITH CTE as ( SELECT dbo.WIPMaster.WorksOrder , dbo.WIPMaster.Parent , dbo.WIPMaterials.Components , dbo.WIPMaster.QtytoMake * dbo.WIPMaterials.Qtyper AS cnt FROM dbo.WIPMaster INNER JOIN dbo.WIPMaterials ON dbo.WIPMaster.WorksOrder = dbo.WIPMaterials.WorksOrder )
SELECT c.WorksOrder , c.Parent , c.Components , T.N FROM cte c INNER JOIN Tally t ON c.cnt >= T.N
__________________________________________________________________ you can lead a user to data....but you cannot make them think ! __________________________________________________________________
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:08 AM
Points: 113,
Visits: 299
|
|
Thanks - I see what you are doing and agree. But unclear about the "Tally" table and how that would be derived ?
Regards Steve
J Livingston SQL (9/29/2012)
something along these lines......?? --=== this relies on a "numbers" or "tally" table --=== http://www.sqlservercentral.com/articles/T-SQL/62867/ by Jeff Moden
; WITH CTE as ( SELECT dbo.WIPMaster.WorksOrder , dbo.WIPMaster.Parent , dbo.WIPMaterials.Components , dbo.WIPMaster.QtytoMake * dbo.WIPMaterials.Qtyper AS cnt FROM dbo.WIPMaster INNER JOIN dbo.WIPMaterials ON dbo.WIPMaster.WorksOrder = dbo.WIPMaterials.WorksOrder )
SELECT c.WorksOrder , c.Parent , c.Components , T.N FROM cte c INNER JOIN Tally t ON c.cnt >= T.N
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 10:08 AM
Points: 113,
Visits: 299
|
|
Sorry - just read the article.
Will have a go at setting this up and testing the data retreival against expected.
Many Thanks Steve
|
|
|
|