Sunday, February 12, 2012

Are these equivalent?

Are the 2 conditions below equivalent? Thanks
dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0)
DavidThey are semantically equivalent, though the first one may perform better.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"David" <dlchase@.lifetimeinc.com> wrote in message
news:eV3YFkqGGHA.596@.TK2MSFTNGP10.phx.gbl...
Are the 2 conditions below equivalent? Thanks
dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0)
David|||Logically they are, but as far as the optimiser is concerned no. You are
using a function on the column AuthNo so that will negate a s on the
index, you'll get an index scan (possibly) which is like a table scan of the
index.
Tony.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"David" <dlchase@.lifetimeinc.com> wrote in message
news:eV3YFkqGGHA.596@.TK2MSFTNGP10.phx.gbl...
> Are the 2 conditions below equivalent? Thanks
> dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
> ISNULL(dbo.tblBillingDetail.AuthNo, 0)
> David
>|||Almost. :)

> dbo.tblBillingDetail.AuthNo IS NULL OR dbo.tblBillingDetail.AuthNo = 0
ISNULL(dbo.tblBillingDetail.AuthNo, 0) = 0
ML
http://milambda.blogspot.com/

No comments:

Post a Comment