C
Can Of Worms
I am beating my brains out on this problem...
I regularly have to access a table in excess of 150 million rows (Via Oracle
Software) that I then extract data in groups of 100,000 to 8 million rows to
analyze. Each row has a
I regularly have to access a table in excess of 150 million rows (Via Oracle
Software) that I then extract data in groups of 100,000 to 8 million rows to
analyze. Each row has a
Code:
field which determines what I am doing with
the row, and 11 different value fields. 3 of the value fields are Long
Integer Types, the remainder are Doubles. (3 groups of [Quantity](Int) [Cost]
[Retail] and 1 group of [Cost] [Retail])
The problem is that the SQL designers that developed the table and how data
is added to the table have different meanings for each of the 11 fields,
depending on what the [Code] is. So in order to do any level of calculations
for [Quantity] [Cost] or [Retail], I have to pick the RIGHT [Quantity] [Cost]
and [Retail] from each row, based on the value of [Code]. I.E., the value I
need to add to the total sum might be [QuantityA] for [CodeX] and [QuantityB]
for [CodeY] and [CodeZ], etc...
There are 83 possible [Code]s, so nested IIF statements are out of the
question. I initially attempted 2 similar custom functions using Select Case
in VBA (one working with Integers for [Quantity] and the other with Doubles
for [Cost] and [Retail]) but when I finally got it to stop crashing with
errors, it just returned a result of "#error", no matter what I did.
The functions worked, as I could test them via Immediate window, however
when using it in a query to build a field, it kept returning "#error" for
every row.
For example: (80 other codes removed)
I pass the [Code], [QuantityA], [QuantityB], [QuantityC] fields as values
into:
Function ChooseValue(Code As String, QuantityA as Integer, QuantityB as
Integer, QuantityC as Integer) As Integer
Select Case Code
Case "ASTZ"
ChooseValue = QuantityA
Case "RPUJ"
ChooseValue = QuantityC
Case "EKRS"
ChooseValue = QuantityB
Case Else
ChooseValue = 0
End Select
End Function
Is there a better way to do this? Am I missing something?
-CoW