IF EXIST

Posts   
 
    
bunzee
User
Posts: 84
Joined: 20-Mar-2007
# Posted on: 15-Jan-2015 00:09:58   

llblgen 2.5 adapter model SQLServer 2008

Say I need to add an error record if that error record does not yet already existed.

To check whether the record exists in SQL, we can do something like IF EXIST (SELECT * FROM ERROR WHERE ERRROR_CODE='123')

How do I do that in LLBLGEN? The only thing I find is closest to achieving this is use GetDbCount and if the result is 0 then proceed. This results in SELECT COUNT(*) in SQL.

My understanding is SELECT COUNT is not as efficient as EXIST( ).

How do I check if EXIST in LLBLGEN?

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jan-2015 06:13:52   

bunzee wrote:

llblgen 2.5 adapter model SQLServer 2008

My understanding is SELECT COUNT is not as efficient as EXIST( ).

How do I check if EXIST in LLBLGEN?

If (select ... exists) does a table scan as well (or pk index scan), so it's not particular faster. You can do a...

SELECT TOP 1 COUNT().... WHERE EXISTS(...)

To do an EXISTS filter (not an IF EXISTS), use FieldCompareSetPredicate.

David Elizondo | LLBLGen Support Team