I have a query that returns a few calculated fields and also uses functions, I am having a problem with the speed that the query runs.
Part of the data is external to our system, since we receive it from the supplier in an Excel spreadsheet and as they are constantly changing the way they assign codes to their products, many of the queries need on the fly functions to assign the values to the filed columns.
One of my queries has the following fields:
Field1--- |Description 1----------|--Field2-|----Description2
A --------|(Myfunction([Level1])|----A ----|----Myfunction([Field1], [Field2])
B --------|-----------------------|----B-----|
C --------|-----------------------|----Z-----|
The first function Myfunction(level1) is not a problem since that for every letter I assign escription using select case statements.
The second function is more complicated and is where i am getting a bit stuck. the code is as follow:
Public Function Myfunction(strField1 As String, strField2 As String) As String
If strField1 = "A" Or strField1 = "B" Or strField1 = "C" Or strField1 = "D" Then
Select Case strField2
Case "A"
Myfunction = "Text1"
Case "B"
Myfunction = "Text2"
Case "C"
Myfunction = "Text3"
Case Else
Myfunction = " "
End Select
Else
Myfunction= " "
End If
End Function
Problem is that I noticed that the query runs a lot slower since I started using the If statement, that was not the case with the first function all created with a Select Case, and I still have another 5 if statements to programme all ranging to up to 8 case declarations for every description.
So I would have:
If Field1=E OR F OR H
case statement
end case
else
If Field1=M OR N OR P
case statement
end case
.
.
.
.
end If
What would be the best way to tackle this?
Part of the data is external to our system, since we receive it from the supplier in an Excel spreadsheet and as they are constantly changing the way they assign codes to their products, many of the queries need on the fly functions to assign the values to the filed columns.
One of my queries has the following fields:
Field1--- |Description 1----------|--Field2-|----Description2
A --------|(Myfunction([Level1])|----A ----|----Myfunction([Field1], [Field2])
B --------|-----------------------|----B-----|
C --------|-----------------------|----Z-----|
The first function Myfunction(level1) is not a problem since that for every letter I assign escription using select case statements.
The second function is more complicated and is where i am getting a bit stuck. the code is as follow:
Public Function Myfunction(strField1 As String, strField2 As String) As String
If strField1 = "A" Or strField1 = "B" Or strField1 = "C" Or strField1 = "D" Then
Select Case strField2
Case "A"
Myfunction = "Text1"
Case "B"
Myfunction = "Text2"
Case "C"
Myfunction = "Text3"
Case Else
Myfunction = " "
End Select
Else
Myfunction= " "
End If
End Function
Problem is that I noticed that the query runs a lot slower since I started using the If statement, that was not the case with the first function all created with a Select Case, and I still have another 5 if statements to programme all ranging to up to 8 case declarations for every description.
So I would have:
If Field1=E OR F OR H
case statement
end case
else
If Field1=M OR N OR P
case statement
end case
.
.
.
.
end If
What would be the best way to tackle this?

Last edited: