Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to call procedure from function. Getting error Invalid use of side-effecting or time-dependent operator in 'INSERT EXEC' within a function. Expand / Collapse
Author
Message
Posted Wednesday, December 4, 2013 4:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 2, 2014 12:28 AM
Points: 12, Visits: 52
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?
Post #1519559
Posted Wednesday, December 4, 2013 5:46 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 11:31 AM
Points: 12,901, Visits: 32,136
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1519575
Posted Wednesday, December 4, 2013 6:04 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Yesterday @ 12:16 AM
Points: 752, Visits: 1,323
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.
Post #1519584
Posted Thursday, December 5, 2013 7:38 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 18, 2014 8:18 AM
Points: 17, Visits: 38
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 :)
Post #1520081
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse