December 8, 2024 at 5:44 pm
Is it more efficient to search on an int than a nullable DateTime?
I have a table where I can choose to search on an int field in the where clause or a nullable datetime field looking for nulls in the where clause. Both methods return the same resultset.
While I am most likely nitpicking, I was wondering if its more efficient?
Thanks
December 8, 2024 at 6:51 pm
Just do a test.
SET STATISTICS TIME,IO ON:
Put code to be tested here.
SET STATISTICS TIME,IO OFF:
Do NOT use this method if any functions that contain the word BEGIN in them. See the following article for an explanation as to why not. For sure, the title is a play on words as to what the real problem is... and that's appropriate for this thread.
https://www.sqlservercentral.com/articles/how-to-make-scalar-udfs-run-faster-sql-spackle
--Jeff Moden
Change is inevitable... Change for the better is not.
December 8, 2024 at 9:35 pm
Thanks. I will do what you suggested.
December 9, 2024 at 3:21 pm
It depends. You'd need to look at the available indexes and whether SQL uses them for the query. So, look at the query plan and see what it "tells" you. If they both scan the full table / clustered index, then neither will be more efficient, they will be the same.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
December 9, 2024 at 4:36 pm
There are no indexes on either field. I am going to create a query plan to see the results. '
I originally asked the question because I have a vague recollection of being told by an instructor from a seminar that I took several years ago where the instructor said that doing an is null on a query is very fast compared to checking the value of a field because the database engineer had to do less work.
Thanks
December 10, 2024 at 8:49 am
This was removed by the editor as SPAM
December 11, 2024 at 3:49 pm
This was removed by the editor as SPAM
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply