Information générale
Catégorie:
The Mere Mortals .NET Framework
Titre:
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
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement