我的SQL标量值函数在以下代码中定义:
CREATE FUNCTION CtrAmount ( @Ctr_Id int )
RETURNS MONEY
AS
BEGIN
DECLARE @CtrPrice MONEY
SELECT @CtrPrice = SUM(amount)
FROM Contracts
WHERE contract_id = @Ctr_Id
RETURN(@CtrPrice)
END
GO
SELECT * FROM CtrAmount(345)
GO
但是当谈到SELECT系列时,我收到了这个错误:
Msg 208, Level 16, State 3, Line 14
Invalid object name 'CtrAmount'.
答案 0 :(得分:2)
Int(10)
- 未知类型
CREATE FUNCTION dbo.CtrAmount
(
@Ctr_Id INT
)
RETURNS MONEY
AS
BEGIN
RETURN (
SELECT SUM(amount)
FROM dbo.Contracts
WHERE contract_id = @Ctr_Id
)
END
GO
SELECT dbo.CtrAmount(345)
GO