DataSet with many OR clauses

I have a little problem with the query I create in Visual Studio Designer.

I need a query with lots of OR 'clauses for the same column.

I found the 'IN' statement , but I don’t know how to use it in Visual Studio Designer:

An example IN:

SELECT EmployeeID, FirstName, LastName, HireDate, City
FROM Employees
WHERE City IN ('Seattle', 'Tacoma', 'Redmond')

I tried to do it as follows:

SELECT [MachineryId], [ConstructionSiteId], [DateTime],
       [Latitude], [Longitude], [HoursCounter]
FROM [PositionData]
WHERE [MachineryID] IN @MachineryIDs

But that will not work.

Is there any other way to handle multiple offers OR?

Many thanks for your help.

+3
source share
1 answer

When executing IN with a parameter, it is used, as shown below, basically the same thing.

declare @SQL varchar(600)
set @SQL = 'select * from tbl where Cast([MachineryID] as varchar(255)) in ('+ @MachineryIDs +')'
EXEC(@SQL)
+1
source

Source: https://habr.com/ru/post/1735886/


All Articles