jmbcreative
Technical User
I am working on createinga UDF and I am stumped. At this point my basic question is this; in a UDF, if I want to use a field that I created within it as part of an equation, do I have to declare the field as a variable?
For example say if I have something like the following;
CREATE FUNCTION Example()
RETURNS int
AS
BEGIN
Declare @ReturnValue
SELECT AVG(ValueA)AS "AvgA", AVG(ValueB) AS "AvgB"
FROM dbo.Example
RETURN @ReturnValue = AvgA - AvgB
END
Is that a legitimate UDF, or do I declare values for the "AvgA", and "AvgB"?
For example say if I have something like the following;
CREATE FUNCTION Example()
RETURNS int
AS
BEGIN
Declare @ReturnValue
SELECT AVG(ValueA)AS "AvgA", AVG(ValueB) AS "AvgB"
FROM dbo.Example
RETURN @ReturnValue = AvgA - AvgB
END
Is that a legitimate UDF, or do I declare values for the "AvgA", and "AvgB"?