Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
From Help..Execute DB UDF: What does
Message
De
04/12/2007 05:55:06
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
From Help..Execute DB UDF: What does
Divers
Thread ID:
01273009
Message ID:
01273009
Vues:
55
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
Fil
Voir

Click here to load this message in the networking platform