Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stuck on what kinds of joins to use... Info inside

Status
Not open for further replies.

SyntaxTerror

Technical User
Jan 5, 2011
52
US
I am pulling from a few temp tables and am not sure how to join them so I get the right results. The goal is, in essence, to make the following calculation:

InventoryCount1+PurchaseOrdersMadeBetweenCount1and2-InventoryCount2=InventoryUsage

Tables:
1) Inventory Counts Temp Table containing CountIDs I need (Trust me, I need this temp table. It goes much deeper than this, but I'm trying to keep it simple)
2) Inventory Transactions Table containing inventory quantities for every individual item for every CountID (I need to join the this to the Inventory Counts Temp Table so I pull the quantities from the right counts)
3) Purchase Orders Temp Table (This contains the purchase order information I need for the time between counts 1 and 2, 2 and 3, 3 and 4, etc. Again, I need this table and am trying not to go too deep)

Basically, my worry is this... One count might contain items that another lacks, so I need to make sure to include all results from Count1 and Count2 (which sounds like a full outer join), but I need to join them to the InventoryCountsTempTable to know what information to pull from InventoryTransactions in the first place.

How can I join Count1 and Count2 to inventory transactions, but also to each other, then also join in the purchase order information without something getting lost or duplicated in the midst of all of the joins?

Sorry if this is confusing :( I'm trying to make it understandable. It's much more confusing if you know the full story.
 
Could you pleas post some example data from all tables and desired result from this data?

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
My goal is to do the following calculation:
CurrentCount(of count0)+PurchaseOrders-CurrentCount(of count1). This will produce the overall inventory utilization by inventory ID. I'd be doing it for multiple weeks, but don't worry about that. Once I can do it for one week, I can do it for all of them. Here are the tables:

#Temp_Counts, from where I'm pulling the count IDs:
TBBCk.png

Week0Count in the InventoryTransactions table (joined on Week0CountID from #Temp_counts)
cuz6d.png

Week1Count in the InventoryTransactions table (joined on Week1CountID from #Temp_counts)
cztIv.png

#Temp_PurchaseOrders (joined on inventory ID)
18g3V.png
 
This calculation would be for Wk1POqty only, so that's what I mean when I mention "PurchaseOrders" in the calculation above.
 
Blarg. Shoot me now. I'm going to dump all of the inventory count data (the IDs of which are in the #temp_counts table) into their own temp table so I can more easily refer to them.
 
I finished the freakin' report! :D 5 temp tables and 9 pages of code later... it's done. ...and runs in 4-6 seconds! :D Not TOO shabby...
 
Congratulations.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top