GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Database  >  Stored Procedures
Go To First  |  Previous Question  |  Next Question 
 Stored Procedures  |  Question 5 of 12    Print  
How can I call function in a stored procedure in SQL Server?

  
Total Answers and Comments: 3 Last Update: May 23, 2008     Asked by: Sridhar Rao 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: praveengowda
 

A function can be called in a select statement as well as in a stroed proc. As function call would return a value we need to store return value in a variable.

Ex:
Assume we have a fuction .. FN_TEST(Date IN VARCHAR2, ID OUR VARCHAR2) RETURN VARCHAR2.
within stored proc declare a variable to store ID.

ID_VAL VARCHAR2(10) :=  NULL;

ID_VAL :=  FN_TEST('1-may-2008', ID_VAL);

hope this helps



Above answer was rated as good by the following members:
ibrarx
October 25, 2006 14:40:57   #1  
Roopesh Nanaware        

RE: How can I call function in a stored procedure in S...

CREATE PROCEDURE [usp_select_Act_Actual_Customer]
(@BranchID [int]
@CompanyID [tinyint])
--WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON

DECLARE @Nulldate [smalldatetime]
SET @Nulldate 0

DECLARE @Serverdate [smalldatetime]
SET @Serverdate GETDATE()

SELECT s.[BranchID] s.[CompanyID] s.[FinancialyearID]
s.[Saledate] s.[Invoiceno] s.[Goodscategoryname]
s.[Bankname] s.[Customercode] s.[Saletype]
s.[Customername] s.[Duedays]
s.[Duedate] s.[Countryname] s.[Totalquantity]
s.[Netvalue] s.[NetvalueInLocal]
s.[Netreceiptamount] s.[Exchangeratetolocal]
FROM [dbo].[fn_Actual_Tsale](0 @BranchID @CompanyID) s
WHERE s.[Receivablefromagent] <> 1

ORDER BY s.[Customername] s.[Saledate]
RETURN(@@ERROR)
END

Ans: This is Procedure And here we Taking record from (fn_Actual_Tsale) function


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
March 10, 2008 04:23:02   #2  
sampra Member Since: February 2008   Contribution: 278    

RE: How can I call function in a stored procedure in SQL Server?
pls explain wd simple example
 
Is this answer useful? Yes | No
May 23, 2008 07:18:26   #3  
praveengowda Member Since: August 2007   Contribution: 3    

RE: How can I call function in a stored procedure in SQL Server?

A function can be called in a select statement as well as in a stroed proc. As function call would return a value we need to store return value in a variable.

Ex:
Assume we have a fuction .. FN_TEST(Date IN VARCHAR2 ID OUR VARCHAR2) RETURN VARCHAR2.
within stored proc declare a variable to store ID.

ID_VAL VARCHAR2(10) : NULL;

ID_VAL : FN_TEST('1-may-2008' ID_VAL);

hope this helps


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape