I have the following stored procedure which runs as expected:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[view_proc]
    (@startdatetime DATETIME,
     @enddatetime DATETIME,
     @ids VARCHAR(MAX)
    )
AS
BEGIN
    SELECT *
    FROM
        (SELECT 
             [sr_datetime], [sr_id], [sr_value], [sr_dst], [sr_source]
         FROM 
             [Powerlink].[dbo].[scada_data]
         WHERE  
             sr_id IN ('M001007', 'M001008', 'M001020', 'M001021')
             AND sr_datetime >= @startdatetime
             AND sr_datetime <= @enddatetime) AS SourceTable 
    PIVOT 
        (MAX(sr_value) 
            FOR [sr_id] IN (M001007, M001008, M001020, M001021)
        ) AS PVT
    ORDER BY 
        sr_datetime
END
I run this procedure using the following line:
EXEC [dbo].[view_proc] 
           @startdatetime = '2018-01-01 01:00:00', 
           @enddatetime = '2018-01-01 02:00:00', 
           @ids = 'M001007,M001008,M001020,M001021'   
However, currently the procedure doesn't use the @ids parameter to change the query in the same way the @startdatetime and @enddatetime parameters change the query.
My question is, what is the simplest way to modify my stored procedure so that it will accept a list of tags as a parameter which it will use to modify the results of my existing query.
I've looked into defining a custom type to use as a parameter, but I can't figure out what syntax I would have to use to represent the data in the call to the procedure.
Any help would be much appreciated.
cheers,
 
     
    