question

GPO avatar image
GPO asked

Are there any functions that are SARGable?

I have this little beastie in a WHERE clause I'm trying to improve (names changed to protect the innocent): and COALESCE(tbl1.datetime1, tbl1.datetime2, tbl2.datetime3,@end_dttm) >= @start_dttm and it got me to wondering whether it's a blanket rule that ALL functions in the where clause can't be used by the query analyser, or a subset of functions that can't be used?
indexesfunctionssargable
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Usman Butt avatar image
Usman Butt answered
I believe till now, whenever you will use a function on a column in WHERE/JOIN clause, you will lose the SARGability. As the function logic has to be applied on the column before the comparison, the statistics and index seek are not applicable. Hence, it always result in an index scan or table scan. In your case, most probably a table scan is expected. If I were you, I would have tried to use a staging temp table to evade such comparison OR would have tried to TWEAK the logic according to the requirements.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

GPO avatar image GPO commented ·
Thanks Usman.
0 Likes 0 ·
GPO avatar image
GPO answered
Interesting discussion about this very topic [here][1] [1]: http://www.sqlservercentral.com/Forums/Topic1226743-203-1.aspx
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Usman Butt avatar image Usman Butt commented ·
Believe me, I was about to enter that discussion as well. But then thought, some other big guns should be responding if that is the case (And they did). I was always thinking of I must be missing something :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.