Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to call Stored Procedure in Function?

Author  Topic 

Weicheng
Starting Member

5 Posts

Posted - 2009-07-21 : 06:14:40
Hi all,

I know sql server doesn't allow calling of stored procedure from within function. But is there any way around it? does OPENQUERY help?

My stored procedure inserts into a table, no value to be returned.

Many thanks

Wei

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-07-21 : 06:23:30
As far as I know no

Functions are extremely limited. They cannot perform any operation in any way that can change data. This means that you can't use dynamic sql or call other objects (except functions)

What are you trying to do exactly?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Weicheng
Starting Member

5 Posts

Posted - 2009-07-21 : 06:28:24
For historic reason, some activity was done in a function, I need to log the activity using stored procedure which insert into log table.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-07-21 : 06:44:30
what do you mean some activity? A function can't change anything so what did it do that you want to log?





Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Weicheng
Starting Member

5 Posts

Posted - 2009-07-21 : 08:47:33
The function write to flat file
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-07-21 : 08:53:39
I'm sorry I don't understand how that could have been possible (writing data to a flat file INSIDE a function).

Are you migrating from a different database vendor?

how are you using the function? Maybe if you want it to *do* something to some data or other object you should rewrite it as a stored proc and use OUTPUT parameters.

you could post the code or explain exactly what you are trying to do. You aren't exactly forthcoming with lots of information.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-21 : 09:03:58
can you use stored procedure to do the job ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -