What I'm after is a summary of amount worked form base, using sql in MS Access, and this is what I want to do:
Sum(IIf(([Time Report].Destination) Like 'D-[Time Report].[Baselocation]',0)) AS [Total WorkFromBase in P2]
This doesn't work, as MS Access doesn't understand regex, and I need the 'D-' appended for it to match.
My options are as far as I'm aware:
- Learn and use VB macro(?) to get the pattern matching correct
- Use a complicated set of IIf statements, as sql doesn't have a native
else if
condition
I don't know VB, and I've only seen one example, which I couldn't make sense of.
If I go for a mass of IIfs then I have something like this
Sum(
IIf(D-[Time Report].[Baselocation] = 'Base1', IIf(
([Time Report].Destination) = 'D-Base1',
IIf(D-[Time Report].[Baselocation] = 'Base2', IIf(
([Time Report].Destination) = 'D-Base2',
IIf(D-[Time Report].[Baselocation] = 'Base3a', IIf(
([Time Report].Destination) = 'D-Base3a' OR ([Time Report].Destination) = 'D-Base3b',
IIf(D-[Time Report].[Baselocation] = 'Base3b', IIf(
([Time Report].Destination) = 'D-Base3a' OR ([Time Report].Destination) = 'D-Base3b', ))
)) AS [Total Work From Base in P1],
Then I end up with a Syntax Error (Missing operator)
type error,
So how can I match the two collumns, and sum when they're similar?