It would be normal to pass the IDs as a sting of numbers and split them using a SplitSting Function.(Google one and create it with any supporting number/tally table.)You code would then be something like:SET ANSI_NULLS, QUOTED_IDENTIFIER ON;GOCREATE PROCEDURE dbo.YourDeviceProc @DateFrom datetime ,@DateTo datetime ,@DeviceIDs varchar(MAX)ASSELECT *FROM Devices DWHERE [timestamp] BETWEEN @DateFrom AND @DateTo AND EXISTS ( SELECT * FROM dbo.SplitString(@DeviceIDs) I WHERE I.IntValue = D.Device_ID )ORDER BY [timestamp];GO-- Example of useEXEC dbo.YourDeviceProc '20101201', '20110110', '1,2,56';
If you only ever need to call the procedure from SQL, or a recent version of .Net, then a table of IDs can be passed directly.You code would then look something like:CREATE TYPE IntTypeTable AS TABLE ( IntValue int NOT NULL);GOSET ANSI_NULLS, QUOTED_IDENTIFIER ON;GOCREATE PROCEDURE dbo.YourDeviceProc @DateFrom datetime ,@DateTo datetime ,@DeviceIDs IntTypeTable READONLYASSELECT *FROM Devices DWHERE [timestamp] BETWEEN @DateFrom AND @DateTo AND EXISTS ( SELECT * FROM @DeviceIDs I WHERE I.IntValue = D.Device_ID )ORDER BY [timestamp];GO-- Example of useDECLARE @t IntTypeTableINSERT INTO @tVALUES (1),(2),(56)EXEC dbo.YourDeviceProc '20101201', '20110110', @t;-- The SP can be called from apps using later versions of .Net by using code found at:-- http://www.sqlservercentral.com/articles/SQL+Server+2008/66554/
You can also pass the IDs as XML.