General information
Category:
The Mere Mortals .NET Framework
Title:
From Help..Execute DB UDF: What does
Hi,
from MM.Net Developers Guide 2.4...
Calling User-Defined Functions (UDFs)
"The code that calls user-defined functions in your database is a little different than the code that calls stored procedures. For example, note the following function:
CREATE FUNCTION GetOrderTotal(@OrderID
int)
RETURNS money AS
BEGIN
RETURN
(SELECT CAST(
SUM(UnitPrice * Quantity *
(1 - Discount)) AS money)
FROM [Order Details]
WHERE OrderID = @OrderID)
END
You need to call this function as follows.
In C#:
public decimal GetOrderTotal(int orderID)
{
IDbDataParameter param = this.CreateParameter("@OrderID", orderID);
IDbDataParameter ReturnValue = this.CreateParameter();
ReturnValue.ParameterName = "@Total";
ReturnValue.Direction = ParameterDirection.ReturnValue;
this.ExecSprocScalar("dbo.GetOrderTotal", param, ReturnValue);
return (decimal)ReturnValue.Value;
}
"
OK...so I have the following UDF which doesn't take an input parameter..
CREATE FUNCTION [dbo].[GetLatestGAAdjustment]
()
RETURNS decimal(5,4)
AS
BEGIN
DECLARE @Result decimal(5,4)
SELECT @Result = (SELECT [Adjustment]
FROM [dbo].[GAAdjustments]
WHERE [DateInserted] = (SELECT Max([DateInserted]) FROM [dbo].[GAAdjustments]))
RETURN @Result
END
How do I call that function and get the returned result? Also, in the C# function above, to which object does the "this" keyword refer?
Thanks,
Nick
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only