Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Can we call function from stored procedure in SQL Server?Give any examples.
Posted
Updated 28-Aug-12 20:16pm
v2
Comments
dan!sh 20-Aug-12 2:49am    
You could have used google or MSDN for this. Have you searched anything?

 
Share this answer
 
Hello,

We can call user defined function from from the stored procedure.
like,

Select dbo.FunctionName(parameters of function) AS Function Return Value
From TableName

Function passing parameter should be in select statement.

Like,

Select A1, A2,A3, dbo.FunctionName(A1,A2) AS AValue From TableName

Thanks,
Viprat
 
Share this answer
 
yes
because,
store procedure consist of one or more sql queries
and In sql query we can call function so, alternately we can say that we can call function in store procedures

here is an example how to call function in sql query
e.g.
SQL
select getdate() --getdate() is sql-function


same way user-defined function can be called.
e.g
SQL
select dbo.fn_OnlyDate() --suppose, onlydate is user-defined sql function; (dbo is schema name because user defined function are accessed using schema name- just for your knowledge.)


Happy Coding!
:)
 
Share this answer
 
Hi,
The following statements are valid in a function:
Valid Operations in SQl-Functions:
Assignment statements.
Control-of-Flow statements except TRY...CATCH statements.
DECLARE statements defining local data variables and local cursors.
SELECT statements that contain select lists with expressions that assign values to local variables.
INSERT, UPDATE, and DELETE statements modifying local table variables.
EXECUTE statements calling extended stored procedures.



--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900