I need to insert a parameter into an IN condition for a particular SQL statement. The actual value of the parameter is a command separated list of ID's that could be 1 ID or multiple ID's. Here is the SQL;
CommandText = @";WITH CTE(ListID, ParentID) AS
(
SELECT ListID, ParentID FROM dvw.DistributionList WHERE ListID IN (@ids)
UNION ALL
SELECT dl.ListID, dl.ParentID FROM CTE AS c INNER JOIN dvw.DistributionList as dl
ON dl.ListID = c.parentID
)
SELECT DISTINCT Email FROM tiger_dev.dvw.Subscriptions AS sub INNER JOIN dvw.Users AS u
ON sub.UserName = u.UserName WHERE u.ActiveUser = 1 and sub.ListID IN
(
SELECT ListID FROM CTE
)
ORDER BY Email"
Here's the issue, The ListID
column data type is int
. When I run the statement I get some conflicting data type issues. Here's a sample one;
Conversion failed when converting the nvarchar
value '4703,4724,4704,4705'
to data type int
.
Is there anyway to go about this without having to create potentially X amount of parameters in the SQL text and set each of them?