S
Steve Wasser
I've got 44 different terminals serving four grades of product each, and
it's been a bitch referencing them. I have one SQL table I'm pulling out
beginning inventory for each location. I've got another stored procedure
that pulls out inventory, ultimately I have to subtract by location, by
product.
Example
opening inventory table stores like:
terminal, starting_unl, starting_prem, starting_diesel, starting_ethanol
record one from the SP looks like:
transaction #, date, terminal, ethanol, premium, regular, diesel
So, I have case statements that look like this to keep a running tally of
what inventory has been pulled out:
case 210:
g210 =
g210+(decimal)dr["LiftingUnl"]+(decimal)dr["DeliveriesUnl"]+(decimal)dr["Adj
ustmentUnl"];
p210 =
p210+(decimal)dr["LiftingPrem"]+(decimal)dr["DeliveriesPrem"]+(decimal)dr["A
djustmentPrem"];
d210 =
d210+(decimal)dr["LiftingDiesel"]+(decimal)dr["DeliveriesDiesel"]+(decimal)d
r["AdjustmentDiesel"];
e210 =
e210+(decimal)dr["LiftingEth"]+(decimal)dr["DeliveriesEth"]+(decimal)dr["Adj
ustmentEth"];
prod[0] = g210+p210+d210+e210;
break;
Reason: the records the SP is pulling aren't sequential, they could be from
any terminal at any time, so I can't use a loop, I have to switch based on
the terminal field, then assign it to it's own products. This example is for
terminal 210. Fine. However, I was thinking for the final calculation it
would have been easy to set up an array with 44 location numbers (stored as
strings), then I could have calculated everything in a final for loop with a
nested foreach like
for (int x, x<44, x++)
{
foreach (string trm in terms)
{
finalunl[x]=finalunl[x]-"g"+trm;
}
}
Trying to make the variable name "g210" (as seen above).Thinking I could
avoid using MORE case statements, and form the name of the grade variable on
the fly. Of course, it didn't work, it just saw me trying to perform math
between a decimal and two strings. Is there a way to build a variable name
on the fly? It would condense 44 MORE case statements down to one nested
loop, and I'd be done.
it's been a bitch referencing them. I have one SQL table I'm pulling out
beginning inventory for each location. I've got another stored procedure
that pulls out inventory, ultimately I have to subtract by location, by
product.
Example
opening inventory table stores like:
terminal, starting_unl, starting_prem, starting_diesel, starting_ethanol
record one from the SP looks like:
transaction #, date, terminal, ethanol, premium, regular, diesel
So, I have case statements that look like this to keep a running tally of
what inventory has been pulled out:
case 210:
g210 =
g210+(decimal)dr["LiftingUnl"]+(decimal)dr["DeliveriesUnl"]+(decimal)dr["Adj
ustmentUnl"];
p210 =
p210+(decimal)dr["LiftingPrem"]+(decimal)dr["DeliveriesPrem"]+(decimal)dr["A
djustmentPrem"];
d210 =
d210+(decimal)dr["LiftingDiesel"]+(decimal)dr["DeliveriesDiesel"]+(decimal)d
r["AdjustmentDiesel"];
e210 =
e210+(decimal)dr["LiftingEth"]+(decimal)dr["DeliveriesEth"]+(decimal)dr["Adj
ustmentEth"];
prod[0] = g210+p210+d210+e210;
break;
Reason: the records the SP is pulling aren't sequential, they could be from
any terminal at any time, so I can't use a loop, I have to switch based on
the terminal field, then assign it to it's own products. This example is for
terminal 210. Fine. However, I was thinking for the final calculation it
would have been easy to set up an array with 44 location numbers (stored as
strings), then I could have calculated everything in a final for loop with a
nested foreach like
for (int x, x<44, x++)
{
foreach (string trm in terms)
{
finalunl[x]=finalunl[x]-"g"+trm;
}
}
Trying to make the variable name "g210" (as seen above).Thinking I could
avoid using MORE case statements, and form the name of the grade variable on
the fly. Of course, it didn't work, it just saw me trying to perform math
between a decimal and two strings. Is there a way to build a variable name
on the fly? It would condense 44 MORE case statements down to one nested
loop, and I'd be done.