|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 17, 2009 1:49 PM
Points: 4,
Visits: 10
|
|
Can I call Stored procedure in User defined function?
- Sarvesh
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
Nope.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 17, 2009 1:49 PM
Points: 4,
Visits: 10
|
|
Thanks for the reply! But can you explain this in detail?
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
Not sure what details you need. You can't run procs from inside UDFs. What details can there be beyond, "can't do that"?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 17, 2009 1:49 PM
Points: 4,
Visits: 10
|
|
| I want to know why it is not possible to do so? There must be some logical Reason/constraint.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
Because UDFs are specifically designed to not do that. Books Online has the details of what they can and cannot do.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, September 10, 2012 10:30 AM
Points: 480,
Visits: 461
|
|
| 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.
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
sarveshcnakhate (1/12/2009) I want to know why it is not possible to do so? There must be some logical Reason/constraint. Because like Excel and some other environments, SQL Server enforces a "strong" definition of functions (the one you should have learned in college) that a Function returns a value and has no side-effects. This is as opposed to the "C-culture" view of functions, that cannot tell the difference between a function and a subroutine, and wherein the whole point of calling functions is to cause side-effects.
And the SQL parser, optimizer and data engine rely heavily on the assumption that functions cannot cause changes in the database while they are being invoked. Almost all of the restrictions in UDF revolve around insuring that this is the case.
-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, September 10, 2012 10:30 AM
Points: 480,
Visits: 461
|
|
| Bingo. That is the same reason that makes the workaround a very bad idea. Thank you, Barry. :)
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
Right Kent. It's a cool trick, but should only be used when truly desperate.
I have seen it cause such things as "undetectable deadlocks". These are really nasty because they really are deadlocks that SQL Server cannot detect. As such they will not go away until you reboot SQL Server (or you can figure out how to kill the OPENROWSET connection).
-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."
|
|
|
|