SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to call procedure from function. Getting error Invalid use of side-effecting or time-dependent...


How to call procedure from function. Getting error Invalid use of side-effecting or time-dependent operator in 'INSERT EXEC' within a function.

Author
Message
mote.ajit2
mote.ajit2
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 53
Hi!

I am trying to call procedure from function but getting following error.

Invalid use of side-effecting or time-dependent operator in 'INSERT EXEC' within a function.

Actually I want table valued function so that I can use it in outer apply to process every left input.

and in that function I am calling another already available procedure.

may be this is not valid here but another alternative I can see is use of cursor which I have to prevent because of possible slowness of query.

Can anybody suggest some workaround?
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28417 Visits: 39963
mote.ajit2 (12/4/2013)
Hi!

I am trying to call procedure from function but getting following error.

Invalid use of side-effecting or time-dependent operator in 'INSERT EXEC' within a function.

Actually I want table valued function so that I can use it in outer apply to process every left input.

and in that function I am calling another already available procedure.

may be this is not valid here but another alternative I can see is use of cursor which I have to prevent because of possible slowness of query.

Can anybody suggest some workaround?


you'll most likely have to change your function into a procedure instead. functions have a number of rules that have to be followed; dynamic SQL is one of the items not allowed, as well as others. if you show us your function or better explain what you are trying to do, we can help better.

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

twin.devil
twin.devil
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2383 Visits: 2674
There is a workaround in which you can use OPENROWSET to call a stored procedure from a function; however, this is in general a bad idea and should be avoided.
roman.asadovsky
roman.asadovsky
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 57
INSERT EXEC is not the best method by itself.
I would try to extract the code from your SP and wrap it in new function, then change the SP to call this function, and in the function you are working on you could just call that other function.
This way you wouldn't duplicate the code, the applications, calling your SP wouldn't be affected and you wouldn't have to use INAERT EXEC.
Of course this method works only if your SP doesn't use dynamic SQL and other things, not allowed to use within a function Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search