@DbLookup with Multiple Keys

Please bare with this message, I have put in detail to make the problem clearer.

Example Data in view:

COLUMN1 | COLUMN2

T002-05012006 | 15

T002-05012006 | 5

T003-05012006 | 10

I am using @DbLookup to return a list of numbers, of which I then perform @Sum to summarise the results. This generally works, apart from Scenario 3 (below is an example of three scenarios):


Scenario 1 (ONE Key):

searchSTR := “T002-05012006”;

LU := @DbLookup(“”:“NoCache”;“”;viewname;searchSTR);

@If(@IsError(LU);0;@Sum(LU))

THIS RETURNS 20 (CORRECT)


Scenario 2 (TWO Keys):

searchSTR := “T002-05012006,T003-05012006”;

LU := @DbLookup(“”:“NoCache”;“”;viewname;searchSTR);

@If(@IsError(LU);0;@Sum(LU))

RETURNS 30 (CORRECT)


Scenario 3 (TWO Keys):

searchSTR := “T001-05012006,T002-05012006”;

LU := @DbLookup(“”:“NoCache”;“”;viewname;searchSTR);

@If(@IsError(LU);0;@Sum(LU))

RETURNS 0 (i.e. Error - NOTCORRECT)

Basically, because the first key doesn’t exist it returns an error (or zero as I handle the error) and doesn’t go onto search for the second key.

We can have ONE or MORE keys.

Any ideas before I start coding an @For loop.

Thanks for any help/advice.

Subject: @DbLookup with Multiple Keys

What you are describing is the expected behaviour – the entire @DbLookup fails at the first failure. If you use, say, three keys and the first key fails, an error is returned. If the second fails, the results for the first key are returned. If the third fails, the results for the first two are returned. If you need ALL of the keys to be returned individually, then you need to do individual lookups – your @For solution.

Subject: RE: @DbLookup with Multiple Keys

Thanks for your reply Stan. I thought that was going to be the case.

@For won’t take long.

Thanks again.