Pass Comma Separated string values as parameter to Stored Procedure in SQL Server

Last Reply 10 days ago By dharmendr

Posted 10 days ago

Hello Team , 

I Need to pass multiple values in single variable  in SQl paramter store procedure.

When im creating Type as variable and declare in SQl paramter . im getting error like Must declare the scalar variable "@GroupName". please help me on this .

CREATE TYPE dbo.GroupName AS TABLE 
(
    groupnames nvarchar(max)
)
GO

Create PROCEDURE [dbo].[UDP_IMRFGroupViewCount]
(
     @GroupName GroupName READONLY
) 
BEGIN 
    SET @GroupName=('SAP1','SAP2','SAP3','SAP4') 
    SELECT Distinct(GroupName) FROM MasterDataOI where GroupName in(@GroupName)
END