title: Pass List of strings to a stored procedure
body: <p>Using, SQL Server 2012, I would like to create a stored procedure, that passes in a list of string and checks it for each entry.Iv added the list to one comma separated string 'UserGroupsAllowedToViewMap'. This was working for one entry but I need to check it for a number of entries.</p>
  
  <pre><code>public DataTable GetMapsWithWorkspaceForUserGroups(int workspaceID, string UserGroupsAllowedToViewMap)
  {
          DataTable mapDets = new DataTable();
  
          SqlCommand oComm = new SqlCommand();
          SqlParameter spParam_WrkSpaceId = new SqlParameter();
          SqlParameter spParam_ViewMap = new SqlParameter();
          SqlParameter[] spParams = new SqlParameter[2];
  
          SqlDataAdapter daUserMaps = new SqlDataAdapter();
          try
          {
              spParam_WrkSpaceId.ParameterName = "@workspaceID";
              spParam_WrkSpaceId.Value = workspaceID;
              spParams[0] = spParam_WrkSpaceId;
  
              spParam_ViewMap.ParameterName = "@ViewMap";
              spParam_ViewMap.Value = UserGroupsAllowedToViewMap;
              spParams[1] = spParam_ViewMap;
  
              oComm = CreateCommand("GetWorkspaceMapDetailsForUserByGroups", spParams, TypeOfConnectionString.GeoAppBuilder);
              daUserMaps.SelectCommand = oComm;
              daUserMaps.Fill(mapDets);
          }
          catch (Exception e)
          {
              throw (e);
          }
          finally
          {
              CloseConnection();
          }
  
          return mapDets;
  }
  
  
  
  
    USE [App]
  GO
  /****** Object:  StoredProcedure [dbo].[GetWorkspaceMapDetailsForUserByGroups]    Script Date: 16/02/2015 10:37:46 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER PROCEDURE [dbo].[GetWorkspaceMapDetailsForUserByGroups]   
      @workspaceID int,
      @viewMap nvarchar(256)
   AS 
  
  SELECT 
    m.*
  FROM 
    GeoAppMapDef m
  WHERE
   m.workspaceID = @workspaceID
   and m.IsDeleted = 0
   and m.ViewMap = @viewMap
  </code></pre>
  
  <p>I am unsure how to iterate through the string in SQL. Ive looked at <a href="https://stackoverflow.com/questions/209686/passing-list-to-sql-stored-procedure">Passing List&lt;&gt; to SQL Stored Procedure</a> and <a href="https://stackoverflow.com/questions/7097079/c-sharp-sql-server-passing-a-list-to-a-stored-procedure">C# SQL Server - Passing a list to a stored procedure</a> but still none the wiser. any help appreciated.</p>