Are you allowed to exec stored procedures within a SQL CTE statement? I\'m a bit new to sql cte queries...
You can also use table variable :
DECLARE @tbl TABLE(id int ,name varchar(500) ,...) INSERT INTO @tbl EXEC myprocedure @param .. with cte as ( SELECT * FROM @tbl ) select * from cte