See if this works for you:ALTER PROC [dbo].[sp_GetTemplatesforProducts](@ProductList VARCHAR(MAX)) ASBEGINSET NOCOUNT ONSET @ProductList=REPLACE(REPLACE(@ProductList,',',''),' ','')-- CTE portion just creates numbers for parsing GUID list;WITH n(n) AS (SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0),a(a) AS (SELECT 0 FROM n CROSS JOIN n x CROSS JOIN n y CROSS JOIN n z),b(b) AS (SELECT 0 FROM a CROSS JOIN a x CROSS JOIN a y),c(c) AS (SELECT (ROW_NUMBER() OVER (ORDER BY b)-1)*36+1 FROM b)SELECT pt.TemplateID, p.ProductID FROM dbo.Products pINNER JOIN dbo.Products_Templates pt ON pt.ProductID = t.ProductIDINNER JOIN c c ON CAST(SUBSTRING(@ProductList,c,36) AS UNIQUEIDENTIFIER)=p.ProductIDWHERE c.c<=LEN(@ProductList)GROUP BY p.ProductID, pt.TemplateIDENDGO