Chap 13, Page 413: UDFs
I replicated the dbo.AveragePrice/dbo.PriceDifference Functions as follows:
USE pubs
CREATEFUNCTION dbo.AveragePrice()
RETURNSmoney
WITHSCHEMABINDING
AS
BEGIN
RETURN(SELECTAVG(Price)FROM dbo.Titles)
END
GO
CREATEFUNCTION dbo.PriceDifference()
RETURNmoney
AS
BEGIN
RETURN @Price-dbo.AveragePrice()
END
But when I try to run the sample query:
SELECT Title,
Price,
dbo.AveragePrice()AS Average,
dbo.PriceDifference ASDifference
FROM Titles
WHEREType='popular_comp'
I get an Error Message:
Msg 4121, Level 16, State 1, Line 1
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.AveragePrice", or the name is ambiguous.
What I am doing wrong, somebody?
|