我正在尝试将函数从一个数据库编写到另一个数据库。这些函数不是我写的,所以不知道初衷。其中之一给我带来了一些麻烦。该函数GetPayDate
只接受一个datetime
参数。但是,当它被调用时:
SET @Minutes = (SELECT SUM(DATEDIFF(n, '1/1/2008', DateTime)) FROM Activities WHERE EmployeeID = @EmployeeID AND dbo.GetPayDate(DateTime, Homework) = @PayDate AND ActivityTypeID = 2)
它被传递了一个额外的参数。这发生在多个位置。它在原始数据库上运行良好,但是当我尝试将其编写为新数据库时,它会抛出:
Msg 8144, Level 16, State 2, Procedure GetTotalHours, Line 8
Procedure or function dbo.GetPayDate has too many arguments specified.
为什么它会在一个数据库中而不是另一个数据库中工作,以及那个额外的参数可能首先在那里做什么?
来自源服务器的定义:
CREATE FUNCTION [dbo].[GetPayDate](@Date DATETIME) RETURNS DATETIME AS BEGIN DECLARE @FirstPayPeriod DATETIME DECLARE @PayPeriodsElapsed INT DECLARE @PayPeriod DATETIME SET @FirstPayPeriod = '5/4/2008' SET @PayPeriodsElapsed = 0 IF @Date IS NULL SET @PayPeriod = NULL ELSE BEGIN SET @PayPeriodsElapsed = CONVERT(INT, DATEDIFF(d, @FirstPayPeriod, @Date) / 14) IF DATEDIFF(d, @FirstPayPeriod, @Date) % 14 > 0 SET @PayPeriodsElapsed = @PayPeriodsElapsed + 1 SET @PayPeriod = DATEADD (d, @PayPeriodsElapsed * 14, @FirstPayPeriod) SET @PayPeriod = DATEADD (d, 5, @PayPeriod) END RETURN @PayPeriod END
来自目标服务器的定义:
CREATE FUNCTION [dbo].[GetPayDate](@Date DATETIME) RETURNS DATETIME AS BEGIN DECLARE @FirstPayPeriod DATETIME DECLARE @PayPeriodsElapsed INT DECLARE @PayPeriod DATETIME SET @FirstPayPeriod = '5/4/2008' SET @PayPeriodsElapsed = 0 IF @Date IS NULL SET @PayPeriod = NULL ELSE BEGIN SET @PayPeriodsElapsed = CONVERT(INT, DATEDIFF(d, @FirstPayPeriod, @Date) / 14) IF DATEDIFF(d, @FirstPayPeriod, @Date) % 14 > 0 SET @PayPeriodsElapsed = @PayPeriodsElapsed + 1 SET @PayPeriod = DATEADD (d, @PayPeriodsElapsed * 14, @FirstPayPeriod) SET @PayPeriod = DATEADD (d, 5, @PayPeriod) END RETURN @PayPeriod END