The last few months I learned so much thanks to all the topics on the forum, thanks to everybody taking the effort answering them. They helped me to create my procedures but now I'm stuck. And related topics haven't given me a solution so far.
Also looked at this page: http://ift.tt/1hyhgrb
Let me explain the situation:
I have created two procedures they work perfectly. They work with temperary tables.
Below I have written out as specific as possible (I hope). If further information is needed I can give this of course.
The two procedures:
1 - Calculations of costs made by own drivers, trucks, fuel consumption > named CostOM
2 - Calculations of revenue and costs on the trip (Revene of orders, Haulage cost, toll cost etc.) > named Trip_margin
What I need to add to the second procedure (Trip_margin) is the calculated amount from the first procedure (CostOM) that is in a column named 'CostOwnMat' (which stands for cost of own material).
Both procedures use the same primary key structure and that is the tripnumber.
They only difference is that procedure 1 can have the same tripnumber multiple times because a trip can be done be 2 or more drivers.
So I need the total sum of the 'CostOwnMat' and return this in the second procedure in a new column named 'total_cost_OM'.
When I have that then I have al the revenue, costs etc. on the trip needed to calculate the margin made on the trip.
I think below is the direction of the solution but how to apply this?
• Table variables (DECLARE @t TABLE) are visible only to the connection that creates it, and are deleted when the batch or stored procedure ends.
• Local temporary tables (CREATE TABLE #t) are visible only to the connection that creates it, and are deleted when the connection is closed.
• Global temporary tables (CREATE TABLE ##t) are visible to everyone, and are deleted when all connections that have referenced them have closed.
• Tempdb permanent tables (USE tempdb CREATE TABLE t) are visible to everyone, and are deleted when the server is restarted.
Aucun commentaire:
Enregistrer un commentaire