I have SQL code that is executing slow
DECLARE @ccode varchar(500)
SET @ccode = '%NIP%'
SELECT [CVN_UID]
FROM [Klasje].[dbo].[VERSION_CATEGORY_XREFS]
WHERE DESCRIPTOR_TEXT LIKE @ccode
Why is SQL Server using nested loops?
This code is working fine, it uses only index scan:
SELECT [CVN_UID]
FROM [Klasje].[dbo].[VERSION_CATEGORY_XREFS]
WHERE DESCRIPTOR_TEXT LIKE '%NIP%'
The slow query is executing 5.5 seconds, without the parameter it's 1.8 seconds.
This query is also working fine:
SELECT [CVN_UID]
FROM [Klasje].[dbo].[VERSION_CATEGORY_XREFS]
WHERE DESCRIPTOR_TEXT LIKE @ccode
OPTION (recompile)