调用 MS SQL 标量值函数,应该在函数前面加上 "dbo.",否则会报 “不是可以识别的 内置函数名称”错误。例如
DECLARE @WhichDB TINYINT;
SELECT @WhichDB = user_GetWhichDB(1);--看看是哪个数据库的
=================================================
--标量值函数
ALTER FUNCTION [dbo].[user_GetWhichDB]
(
@UserId INT = 0
)
RETURNS TINYINT
WITH EXECUTE AS CALLER
AS
BEGIN
DECLARE @WhichDB TINYINT;
SET @WhichDB = 1;
IF @UserId >= 115098
SET @WhichDB = 2;
RETURN (@WhichDB);
END