I ran your code, but it produced NULL values for @SqlStmt.
Here's a quick tally table solution:
DECLARE @BigArray varchar(max)
SET @BigArray = ',1,2,3,5,7,11,13,17,19,23,29,31,'
;with Array AS (select substring(@bigArray,N+1,charindex(',',@bigArray,N+1)-(N+1)) as element
from dbo.tally
where substring(@bigArray,N,1) = ','
and N < len(@bigArray)
)
-- insert into Sometable
select * from Array
where element in (1,3,13,31)
My question is: If you know in advance that those four elements (1,3,13,31) are the only ones that matter, why not just insert them?