gpt4 book ai didi

sql - 如何在SQL Server 2008中执行函数

转载 作者:行者123 更新时间:2023-12-01 21:59:39 26 4
gpt4 key购买 nike

我构建了一个函数并尝试执行它...但发生了一些错误

CREATE FUNCTION dbo.Afisho_rankimin(@emri_rest int)
RETURNS int
AS
BEGIN
Declare @rankimi int
Select @rankimi=dbo.RESTORANTET.Rankimi
From RESTORANTET
Where dbo.RESTORANTET.ID_Rest=@emri_rest
RETURN @rankimi
END
GO
SELECT dbo.Afisho_rankimin(5)AS Rankimi
GO

执行时出现的错误是:

Msg 2714, Level 16, State 3, Procedure Afisho_rankimin, Line 11
There is already an object named 'Afisho_rankimin' in the database.

据说:

Can not find column "dbo", or the user defined function, or aggregate "dbo.Afisho_rankimin", or the name is ambiguous

最佳答案

您的数据库中似乎还有其他名为 Afisho_rankimin 的内容,因此未创建该函数。尝试将您的函数称为其他名称。例如

CREATE FUNCTION dbo.Afisho_rankimin1(@emri_rest int)
RETURNS int
AS
BEGIN
Declare @rankimi int
Select @rankimi=dbo.RESTORANTET.Rankimi
From RESTORANTET
Where dbo.RESTORANTET.ID_Rest=@emri_rest
RETURN @rankimi
END
GO

请注意,您只需调用一次,而不是每次调用该函数时。之后尝试调用

SELECT dbo.Afisho_rankimin1(5) AS Rankimi 

关于sql - 如何在SQL Server 2008中执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21358306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com