What would be the most efficient way to query and index for the following:
SELECT * Persons.LastName A-D
SELECT * Persons.LastName E-L
SELECT * Persons.LastN
You predicate is sargable.
If you run this query on an indexed field:
SELECT *
FROM persons
WHERE last_name >= 'a'
AND last_name < 'e'
it produces the following plan:
|--Nested Loops(Inner Join, OUTER REFERENCES:([MYDB].[dbo].[PERSONS].[ID]) OPTIMIZED)
|--Index Seek(OBJECT:([MYDB].[dbo].[PERSONS].[IX_PERSONS_LAST_NAME]), SEEK:([MYDB].[dbo].[PERSONS].[LAST_NAME] >= 'a' AND [MYDB].[dbo].[PERSONS].[LAST_NAME] < 'E'), WHERE:([MYDB].[dbo].[PERSONS].[LAST_NAME] like '[a-d]%') ORDERED FORWARD)
|--Clustered Index Seek(OBJECT:([MYDB].[dbo].[PERSONS].[IX_PERSONS_LAST_NAME]), SEEK:([MYDB].[dbo].[PERSONS].[ID]=[MYDB].[dbo].[PERSONS].[ID]) LOOKUP ORDERED FORWARD)
which is equivalent to running this query:
SELECT *
FROM persons
WHERE last_name >= 'a'
AND last_name < 'e'