September 25, 2015 at 10:14 am
In a t-sql 2012 sql, I see the following in a where statement:
where ISNULL(I.Active, 0) = 1 AND ISNULL(AN.AccountNumber,0) IN (@Account).
Would you tell me what the ISNUll function is doing in the both isnull tests listed above?
September 25, 2015 at 10:23 am
"Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime."
Here's the article on Books Online (BOL). To get there, just select the keyword and press F1 in SSMS.
https://msdn.microsoft.com/en-us/library/ms184325(v=sql.110).aspx
September 25, 2015 at 10:23 am
wendy elizabeth (9/25/2015)
In a t-sql 2012 sql, I see the following in a where statement:where ISNULL(I.Active, 0) = 1 AND ISNULL(AN.AccountNumber,0) IN (@Account).
Would you tell me what the ISNUll function is doing in the both isnull tests listed above?
Nothing other than preventing the effective use of an index.
Also, the "IN (@Account)" can be rewritten as "= @Account".
Edit... The "ISNULL(AN.AccountNumber,0) IN (@Account)." would allow nulls to be included if @Account = 0
A better way to write would be
AND (AN.AccountNumber = @Account OR (@Account = 0 AND AN.AccountNumber IS NULL))
OPTION(RECOMPILE)
September 25, 2015 at 10:26 am
Jason A. Long (9/25/2015)
wendy elizabeth (9/25/2015)
In a t-sql 2012 sql, I see the following in a where statement:where ISNULL(I.Active, 0) = 1 AND ISNULL(AN.AccountNumber,0) IN (@Account).
Would you tell me what the ISNUll function is doing in the both isnull tests listed above?
Nothing other than preventing the effective use of an index.
Also, the "IN (@Account)" can be rewritten as "= @Account".
In fact, the ISNULL(I.Active, 0) = 1 can be written as I.Active = 1 with the exact same results.
September 25, 2015 at 11:34 am
Luis Cazares (9/25/2015)
"Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime."--
I like this version:
Give a man a fish and he will eat for a day. Teach him how to fish, and he will sit in a boat and drink beer all day.
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply