you need begin
and end
wrapped around the function body (after the as
)
views:
275answers:
3No matter what you do, you will not be able to transform a procedure into a table valued function nor into a view. There are severe restriction around what a function is allowed to do and what not. Because a TVF or a view can be combined with any other statement, like appear in a SELECT as a subquery, or be part of an UPDATE/INSERT/DELETE and so on and so forth, there are certain behavior restrictions imposed on functions, specially when in comes to execution side effects. Procedure son the other hand are free as a bird.
The only thing you can do is to capture the output of a procedure into a table, using INSERT ... EXEC... and that's it, with the extra added restrictions that there cannot be another INSERT ... EXEC ... nested.
Eeverything you posted points that fetchCcoverageByState_V2 must be a table valued function, and that is the only avenue you should pursue.
Try using OPENROWSET, as in this question. I thought I had blogged about it some time, but perhaps not.
http://stackoverflow.com/questions/653714/how-to-select-into-temp-table-from-stored-procedure
Remember to upvote Aaron's answer.