Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Creating a view from 2 joined tables - inserting multiple lines Expand / Collapse
Author
Message
Posted Thursday, September 27, 2012 1:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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.

Post #1365065
Posted Thursday, September 27, 2012 1:35 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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?
Post #1365066
Posted Thursday, September 27, 2012 1:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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;


Post #1365067
Posted Thursday, September 27, 2012 1:42 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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
Post #1365069
Posted Thursday, September 27, 2012 1:50 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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
Post #1365075
Posted Thursday, September 27, 2012 1:56 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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



Post #1365078
Posted Saturday, September 29, 2012 10:24 AM


UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP 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 !
__________________________________________________________________
Post #1366205
Posted Monday, October 01, 2012 3:48 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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

Post #1366443
Posted Monday, October 01, 2012 4:09 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1366459
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse