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.
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
I am unsure how to iterate through the string in SQL. Ive looked at Passing List<> to SQL Stored Procedure and C# SQL Server - Passing a list to a stored procedure but still none the wiser. any help appreciated.