I have the following query:
SELECT
M.Col7,
M.Col8,
M.Col9,
M.Col10
FROM [MyTable] M
WHERE M.Col1 = COALESCE(@Col1, M.Col1)
AND M.Col2 = COALESCE(@Col2, M.Col2)
AND M.Col3 = COALESCE(@Col3,
M.Col3)
AND M.Col4 = COALESCE(@Col4,
M.Col4)
AND M.Col5 = COALESCE(@Col5,
M.Col5)
AND M.Col6 LIKE COALESCE(@Col6, M.Col6) +'%'
I have a combined non clustered index on col7,8,9,10 columns. The query is running fine if I remove the where clause. But as soon as I put the where clause the query is taking long time to execute. My table has 200 K rows. Now I am thinking to put a single non clustered index with columns in this order Col1,2,3,4,5,6. Am I doing right to make it fast or what should be the best option for this?