Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
From Help..Execute DB UDF: What does
Message
 
À
04/12/2007 05:55:06
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01273009
Message ID:
01273496
Vues:
11
Nick,

>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?

In this case you just need to create the output parameter like this:
>public decimal GetLatestGAAdjustment()
{
   IDbDataParameter ReturnValue = this.CreateParameter();
   ReturnValue.ParameterName = "@Adjustment";
   ReturnValue.Direction = ParameterDirection.ReturnValue;

   this.ExecSprocScalar("dbo.GetOrderTotal", ReturnValue);

   return (decimal)ReturnValue.Value;
}
Kevin McNeish
Eight-Time .NET MVP
VFP and iOS Author, Speaker & Trainer
Oak Leaf Enterprises, Inc.
Chief Architect, MM Framework
http://www.oakleafsd.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform