SQL User Defined Functions

  • Thread starter Thread starter sandy
  • Start date Start date
S

sandy

Dera all, i have created a UDF in SQL server and would to
call it using following SQL statement.

Any ideas how can i do that? The issues is that i can call
a UDF by specifiying the parameter etc.. but in this case,
i don't need to pass any parameters...since i am using UDF
in select statement.. i don't know how to call fill the
dataset in this case...

SELECT
B.BRAND_ID, SEGMENT_ID, B.LINE_ID,
DBO.GetDeliveryFeesF(B.BRAND_ID, SEGMENT_ID) AS
DELIVERYFEES
From Brand B

*****************************
create FUNCTION GetDeliveryFeesF ( @BrandID int, @segID
int )
RETURNS int
AS
BEGIN

RETURN(select
case
when b.chassis='Y' and deliveryfee is not null
then
b.DeliveryFee
Else
(Select isNull(sb.delivery_fee,
pl.delivery_fee) from brand b, Segment_Brand sb,
productline pl where sb.brand_id = b.brand_id AND
b.brand_id = @BrandID and sb.segment_id =@segID and
pl.line_id = b.line_id)
end As DeliveryFee
from brand b
where b.brand_id = @BrandID
)
END
***********************************************
 
If you use the DataAdapter configuration wizard, simply
cut and paste you code into it. You can reference UDF's
just like anything else... dbo.MyFunction(someColumn)

If you aren't using the wizard, just use th SQL Statement
as your command text and it'll work. What error are you
getting when you try to run it?

Good Luck,

Bill
 
I was getting
"Function not recognized error"
-----Original Message-----
If you use the DataAdapter configuration wizard, simply
cut and paste you code into it. You can reference UDF's
just like anything else... dbo.MyFunction(someColumn)

If you aren't using the wizard, just use th SQL Statement
as your command text and it'll work. What error are you
getting when you try to run it?

Good Luck,

Bill
.
 
Back
Top