Database server is Microsoft SQL Server, but I don’t have Administrator access to it.
So, I don’t know which version, and I don’t know which indexes exist.
To access the database, I am using ADO.
Here is the SQL statement:
-- Get master objid and order_number and activity time
SELECT A.objid,
A.order_number,
F.entry_time
-- From these tables
FROM dbo.table_master as A,
dbo.table_activity as F
-- link of the tables
WHERE F.objid = A.objid
-- Retrieve code = 1900 only
AND F.code = 1900
-- Which have info like this:
AND F.info LIKE '%to SUPPORT.'
-- And entry time between these times:
AND F.entry_time >= '2011-10-01 00:00:00'
AND F.entry_time <= '2011-12-05 23:59:59'
-- We want the earliest entry (because there might be multiple code = 900 and info like)
ORDER by F.entry_time
Is it possible to optimize this?
Thanks
Here are things you could do differently:
RIGHT(f.info, 11) = 'to SUPPORT.'instead ofF.info LIKE '%to SUPPORT.'INNER JOINas @xQbert suggestedBETWEENfor the date range instead of the combination of<and>.In my testing, the only one that made a difference in performance was the first option. All 3 items will generate the same execution plan, however, the
RIGHTfunction was around 10x quicker in my test in terms of actual execution time. I’m usingSTATISTICS TIMEto test.If possible, I would try to get access to look at the indexes. Having the tables properly indexed will make a way bigger difference than the
RIGHTfunction.