Tuesday, 18 April 2017

MSSQL - Pass multiple values to single paramenter in stored procedure - pass integers


Watch on YOUTUBE


1. Stored Procedure

CREATE PROCEDURE TestProductIDs
    @IDList varchar(max)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    Declare @SQL varchar(max) = 'Select * from Product where ProductID in (' + @IDList + ')';
    Exec (@SQL);
END
GO

2. Calling Stored Procedure

exec TestProductIDs '2, 5, 7'

No comments:

Post a Comment