@Dblookup always return value of the 1st row

Hi, When I want to create a new contract, I need to check if there are any repeated contract no in database.

The column ContractNo is the 1ST and sorted column in Contract View(Actually it is the 2nd, but the 1st one is computed s/n).

I use the following statement:

@DbLookup(“”:“NoCache”;“”; “ContractView”;PContractNo;1;[FAILSILENT]);

Where PContractNo is the field name of the contract no and 1 is the column no.

But what I got is always the value of 1st row.

If everything is ok, it should return the same contract no if having repeated contract no.

Thanks!

Subject: @Dblookup always return value of the 1st row

So what happens if you putDbLookup(“”:“NoCache”;“”; “ContractView”;PContractNo;2;[FAILSILENT]);

or put

DbLookup(“”:“NoCache”;“”; “ContractView”;PContractNo;“PContractNo”;[FAILSILENT]);

Subject: RE: @Dblookup always return value of the 1st row

You say the column displays the field ContractNo, but your lookup key comes from the field PContractNo.Don’t use FAILSILENT in this case – if there is a failure you want to know what it is. Once you’ve got the formula perfected, then you can FAILSILENT. Although, in this case, it’s better not to FAILSILENT, since an error doing the lookup is precisely what you need to tell you that the lookup key wasn’t there. Who cares about the value returned by the lookup? Just see whether you got an error – if so the key is unique.

I don’t understand what you mean by “computed s/n”. Is it a sorted column? @DbLookup searches for the key value you supply in the first sorted column – whether it’s computed or not. And when you ask for column number 1 back – why are you expecting to get column 2 instead?

There is no way that @DbLookup will just grab the value from the first row of the view. If you’re getting a value from the first row, it’s because the first sorted column in the first row matched your key. Remember too that @DbLookup will return all the matching entries. I don’t know how you’re displaying your return value, but use @Implode on it – you may be getting multiple rows back.

Subject: RE: @Dblookup always return value of the 1st row

Hi, Andre Guirard:Thanks. I made a mistake. The computed s/n should be the 1st column of view. After I change Contract No. to the 1st column, it works.

Thanks