How can I get a local variable that's a list in a stored procedure?
What I'm totally stopped on is I don't see any equivalent of a List is SQL. Is there a way to build all this up in a list?


So a list in SQL Server is basically a table. You can use table-valued parameters to pass in your complete list from C#. You basically just create a table type to define that list you are passing in, see the example in the MSDN link.

You would just need to take each requirement you list in your question or that the C# is performing, and write the query to pull the correct values from your tabled-values list and create your INSERT, DELETE, and UPDATE statements based on those values.

So for


  Any domain in the passed in list that is not in CompanyDomains is added to CompanyDomains.


Something like:

INSERT INTO CompanyDomains (&lt;column list&gt;
SELECT &lt;column list&gt;
FROM @TableParameter t
WHERE NOT EXISTS ( SELECT domain FROM CompanyDomains cd WHERE t.domain = cd.domain );