Функция не может выполнять какие-либо операции DML над таблицей. Я удалил оператор INSERT
ALTER FUNCTION dbo.Intrest
(@loan MONEY, @interest MONEY)
RETURNS INT
AS
BEGIN
DECLARE @returnValue INT
SET @returnValue = (@loan) * (@interest)
RETURN @returnValue
END
GO
Переменные не обязательны. Ваш Stored Procedure
можно упростить до
ALTER PROCEDURE Getoutput
(@loanamount MONEY, @interestrate MONEY)
AS
BEGIN
INSERT INTO Loan (Outputs, Loan_amount, Interest_rate)
SELECT Loan_id, Loan_amount, dbo.Intrest (Loan_amount, @interestrate)
FROM Loan
WHERE Loan_amount = @loanamount
RETURN @@identity
END