0

I am still kind of a beginner here but I created this UDF:

USE NorthWind
GO
IF EXISTS(SELECT name FROM SYSOBJECTS
                 WHERE name='SaleAfterDiscount'
                 AND type ='FN')
BEGIN 
DROP FUNCTION SaleAfterDiscount;
END
GO
CREATE FUNCTION SaleAfterDiscount(@pPrice AS MONEY, @pQty AS SMALLINT, @pDiscount AS REAL)
RETURNS MONEY AS 
BEGIN
DECLARE @SaleAfterDiscount MONEY;
SET @SaleAfterDiscount=(@pPrice*@pQty*(1-@pDiscount));
RETURN @SaleAfterDiscount;
END;

Then I go to use this UDF to get a value and I get this error that says "The Multi-Part Identifier "dbo.SaleAfterDiscount" could not be bound. I am not sure what I did wrong. Can anyone help?

Zachary
  • 1
  • 2

1 Answers1

1

Since the CREATE FUNCTION does not specify a schema, it is likely it being created in a different schema (depends on your user config).

Try changing the CREATE to look like below

CREATE FUNCTION dbo. SaleAfterDiscount

RnP
  • 390
  • 1
  • 8