The Result Data Newsletter   
Volume 706 - June 2007   
© Copyright 2007 Result Data Consulting, Ltd.  614-505-0770  www.resultdata.com   

    Result Data Home Page  |  Newsletter Archive  |  Upcoming Events  |  Classes & Workshops  |  Request Information
Upcoming Events:  MOBOUG: 8/1, Business Objects BI Lunch-n-Learn: 8/1, Microsoft SQL Server User Group: 9/21

Return to Newsletter Contents...

 

A Better Way EXISTS

by: Sean Beal, Senior Consultant, CRCP

Regularly, the COUNT(column) function is used to evaluate not only the number of rows returned, but also to check whether any rows are returned at all.  As an example, consider the following (based on the Northwind database):

if (select count(*) from orders where customerid = 'DRACD') > 0

print 'Drachenblut Delikatessen has orders'

If we care only that there is at least one row, a much better way to code this is to use the EXISTS keyword:

if exists (select * from orders where customerid = 'DRACD')

print 'Drachenblut Delikatessen has orders'

The reason is this:  the COUNT() function must read all rows that fit our requirements; in this case, where the customer id is equal to ‘DRACD’.  The EXISTS function allows our IF statement to evaluate to true after finding only one record.

Queries can in a similar way be optimized by using the positive EXISTS rather than the negative NOT EXISTS where possible, because EXISTS evaluates to true based on one record, whereas NOT EXISTS must evaluate all the records in order to prove non-existence.

Go to Top  |  Return to Newsletter Contents

 

The Result Data Newsletter is published approximately once a month to share the latest information on business intelligence, data management and CRM. There should be a link below to allow you to change or remove yourself from our list. We take your requests very seriously. If you have any difficulty please contact us at 614-505-0770 and we will make sure that your request is handled properly. This is not intended to be an unsolicited message and you can reach us in person if needed.

© Copyright 2007 Result Data Consulting, Ltd. - All Rights Reserved
All trademarks and copyrights are the property of their respective owners. This information is provided without warranty.
Announcements
Next MOBOUG Meeting
The next Mid-Ohio Business Objects User Group (MOBOUG) meeting is August 1st, 2007.  Call 614-505-0770 or click here to reserve your seat.
Next Business Objects BI Seminar is a Lunch-n-Learn
Join us for a lunch-n-learn after the MOBOUG meeting on August 1st.  Call 614-505-0770 or click here to reserve your seat.
Summer Training Special
Beat high gas prices with Result Data Training.  Schedule and attend any public training class now through September and receive a FREE fuel card for up to $200 (restrictions apply).  Call 614-505-0770 for further details and restrictions.
Next Microsoft Data Management & BI Seminar
The next free Microsoft BI seminar on is Sept. 21, 2007.  Call 614-505-0770 or click here to reserve your seat.
Looking for a Few Good Men and Women
Join our award winning team of Business Intelligence consultants and .Net Software developers.

Send your resume and salary requirements to:
jobs@resultdata.com