My current solution is along the lines of
SELECT * FROM TableName WHERE ID in (1, 2, 3)
This cannot be translated to
SELECT * FROM TableName WHERE ID in (@IDs)
The connection to the database cannot make temporary tables or functions. Is there any way to perform a parameterized query with multiple values in a single statement without modifying the database?
The reason for parameterizing the query is that not every case will be searching for a numeric field. Therefore the values that are received can contain any text. Is there any way to replace special characters in the input so that there is no risk of returning information the user should not have access to?
EDIT: More Info
SELECT *
FROM [dbo].[Parts]
WHERE IsDeleted = 0
AND [PartNumber] IN (@PartNumbers)
ORDER BY [PartNumber] ASC
In the above SQL the query is read from a text file and groovy is used to replace @PartNumbers
with 'PartNumber1', 'PartNumber2'
But the value the groovy script writes is an inbound message property. So in this case the user made a GET Rest request /myservice?partnumbers=PartNumber1,PartNumber2
this is easy to inject, if the parameter was partnumbers=PartNumber1' or '% then the result would be
SELECT *
FROM [dbo].[Parts]
WHERE IsDeleted = 0
AND [PartNumber] IN ('PartNumber1' or '%')
ORDER BY [PartNumber] ASC
Which would return too much information.