I am getting error on % operator while executing. Can you please help me to write proper way.
SET @sql = N'DELETE TOP(1000) FROM ' + @tableName + ' WHERE ItemId
in (Select ItemId from dbo.History_Item
WHERE (
[FullyQualifiedName] LIKE ''' + @machine_DS + '.%'''
OR
[FullyQualifiedName] Like '''+ @machine_Kpi + '.%'''
)
)
AND datetime between'''+ @startDate +''' And '''+ @endDate +'''
I followed this link How to parameterize query with like operator in Sql Server
But unable set it perfectly. I know it is duplicate query but I am facing trouble to set it.
It should be something like this:
SQL Code
SQL Code without injection
SQL Output