I am writing a procedure and find myself using the same select
statement with the same where
clause a lot. Currently the table holds over 55000 rows and grows about 100 or so rows each day. The two where
clauses cut the data down to a few hundred rows in total.
I run the exact same select statement over a dozen times and the data results will always be the same, within the same run. Would it be better, performance-wise, to keep running the same select statement or should I do an insert into select
to fill a temp table with only the data I need and pull from there instead?
Select statement ran (with some some IDs redacted):
SELECT WorkDay1, WorkDay1Brea, StartBreak, StrtTm
FROM dbo.DriverTimes
WHERE DriverTime.DrvrID = @DriverID
AND CONVERT(VARCHAR(12), dtwrkd, 112) = CONVERT(VARCHAR(12), @StartDate, 112)
AND PryllID IN (
ListOfIDs
);
This select is ran a total of 8 times for each Driver and there are 40 some odd drivers.
where
clause cuts that down to just over 50000, the secondwhere
clause will cut that down to just a few hundred columns. The secondwhere
clause is doing a compare against a part of a multi-columnPK
.The table it's self contains over 5500 rows, the first where clause cuts that down to just over 50000
select
query with the twowhere
clauses and explain how you use it further?