|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 373,
Visits: 273
|
|
Has anyone tried calling a stored procdure from a user defined function. I have a procedure as Proc_XXX with 7 parameters if i do exec Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007') i am getting the result set. Is it possible to have the same results when calling thru a function .
call Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007')
any help on this will be greatly appreciated. TIA
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 21,376,
Visits: 9,584
|
|
Can't be done... and shouldn't be done (by design).
What exactly do you want to do?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 8:45 PM
Points: 7,002,
Visits: 13,999
|
|
Ninja's_RGR'us (12/8/2008) Can't be done... and shouldn't be done (by design).
What exactly do you want to do?
Can't be done in T-SQL functions. You might be able to get away with it through CLR (depending on what is being done). That being said - totally agree about the SHOULDN'T part...
---------------------------------------------------------------------------------- Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 1:14 PM
Points: 28,
Visits: 168
|
|
ishaan99 (12/8/2008) Has anyone tried calling a stored procdure from a user defined function. I have a procedure as Proc_XXX with 7 parameters if i do exec Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007') i am getting the result set. Is it possible to have the same results when calling thru a function .
call Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007')
any help on this will be greatly appreciated. TIA
Not sure how you feel about calling functions from functions but you could create this
Func_XXX(.....) Insert current proc code here making the proc a proper function Proc_XXX(.....) Select * From Func_XXX(....) Use Func_XXX from your other function.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 1:01 PM
Points: 2,023,
Visits: 4,947
|
|
laubenth (12/8/2008)
ishaan99 (12/8/2008) Has anyone tried calling a stored procdure from a user defined function. I have a procedure as Proc_XXX with 7 parameters if i do exec Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007') i am getting the result set. Is it possible to have the same results when calling thru a function .
call Proc_XXX(null,null,null,null,null,'1/1/1998','1/1/2007')
any help on this will be greatly appreciated. TIANot sure how you feel about calling functions from functions but you could create this Func_XXX(.....) Insert current proc code here making the proc a proper function Proc_XXX(.....) Select * From Func_XXX(....) Use Func_XXX from your other function.
If the code contains any insert/update/delete statements to permanent tables (e.g. not table variables and not temporary tables), it isn’t possible. Inside a function you can not modify data and can not execute stored procedure.
Adi
-------------------------------------------------------------- To know how to ask questions and increase the chances of getting asnwers: http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 21,376,
Visits: 9,584
|
|
| Exactly... that's because the servers needs to assume that the state of the DB and data will not change by calling the function (again, by design because the server would basically need to recompile the queries after each call to the function... which happens on every rows in the select). If you need to do such modifications, it needs to be done inside a proc.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 30, 2013 1:26 PM
Points: 2,359,
Visits: 3,293
|
|
It CAN be done if you use OPENROWSET with a loopback linked server. If you should is another question.
N 56°04'39.16" E 12°55'05.25"
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 21,376,
Visits: 9,584
|
|
... and you can open fire on the server run with a shotgun and call your service rep for a free replace of the servers too.
I wouldn't try that either!
MS designed it that way for a very specific reason, I can't recomend it enough to not do that!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 30, 2013 1:26 PM
Points: 2,359,
Visits: 3,293
|
|
I have a function where I call "sp_who2" and take database and username as parameters to the function. Works great.
N 56°04'39.16" E 12°55'05.25"
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Today @ 7:02 PM
Points: 21,376,
Visits: 9,584
|
|
| I know... untill you start using sps that do DML, then you canget seriously screwed if you're not carefull... unsupported, I find another way!
|
|
|
|