I am trying to get data in batches. This one goes pretty fast:
select top 10 * from Table1 where (subject like '%Recap%' or subject like '% CP %') and Body like '%Details:%' and ToAddr like '%[email protected]%'
Now when trying to get that data in batches it takes around two minutes. The query is extremely:
SELECT * FROM (
select*, ROW_NUMBER() OVER (ORDER BY name) as row from Table1 where (subject like '%Recap%' or subject like '% CP %') and Body like '%Details:%' and ToAddr like '%[email protected]%'
) a WHERE a.row > 10 and a.row <= 20
Am I getting the batches in a wrong way?
Just discovered even this is pretty slow:
select top 10 *, ROW_NUMBER() OVER (ORDER BY id) as row from Table1 where (subject like '%Recap%' or subject like '% CP %') and Body like '%Details:%' and ToAddr like '%xxx%'
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
TOP 10 *
FROM
Table1
WHERE
(
Table1.subject LIKE '%Recap%'
OR Table1.subject LIKE '% CP %'
)
AND Table1.Body LIKE '%Details:%'
AND Table1.ToAddr LIKE '%[email protected]%'