【问题标题】:Multiple parameters error while creating function in SQL Server在 SQL Server 中创建函数时出现多个参数错误
【发布时间】:2018-01-21 10:17:01
【问题描述】:

我创建了一个函数,现在我想传递静态值,我想在函数中添加参数,但是在调用函数后它开始抛出错误:

过程或函数 dbo.hello 指定的参数过多。

功能:

Create Function dbo.hello
    (@InputstartDate Date, @InputendDate Date)
Returns @attendanceTemp table(STUD_NAME VARCHAR(50), 
                              ATTD_DATE DATE , 
                              attd_DATEs DATE,
                              Attendance VARCHAR(20))
As
Begin
    Declare @startDate DATE 
    SET @startDate = @InputstartDate

    Declare @endDate Date
    SET @endDate = @InputendDate

    Declare @dateDifference INT
    SET @dateDifference = DATEDIFF(day, @startDate,@endDate) ;

    Declare @count INT
    SET @count = 0

    DECLARE @myTable TABLE (STUD_ID int,
                            countdd int,
                            STUD_NAME varchar(50),
                            AttDate Date
                           )

    While @count <= @dateDifference
    Begin
        Insert Into @myTable (STUD_ID, countdd, STUD_NAME, AttDate) 
        Values (1, 123, 'HAIDER', @startDate)

        Set @count = @count +1
        Set @startDate = DATEADD(day, 1, @startDate)
    End

    Insert Into @attendanceTemp 
        Select 
            tb.STUD_NAME, ATTD_DATE, tb.AttDate,
            Case
               When att.DETAIL Is Null
                  Then 'ABSENT'
               When att.DETAIL = 'ATTENDACE' 
                  Then 'PRESENT' 
            End As Attendance 
        from 
            @myTable tb
        Left Join 
            ATTENDANCE att on tb.AttDate = att.ATTD_DATE
        Where 
            att.STUD_ID = 1 or att.STUD_ID IS NULL 

    Return
END

调用函数:

select * 
from dbo.hello('2014-04-01', '2014-04-10');

错误:

过程或函数 dbo.hello 指定的参数过多

【问题讨论】:

  • 我无法重现这个问题,该功能工作正常。您是否针对正确的服务器和数据库运行 select 语句?
  • select * from sys.objects where name = 'hello', sp_helptext 'dbo.hello'

标签: sql sql-server sql-server-2008 sql-server-2005


【解决方案1】:

可能您首先创建的函数只有一个参数。 然后修改了'create function'脚本,忘记部署了?

我愿意;

1. DROP FUNCTION dbo.hello
2. CREATE FUNCTION dbo.hello, with you script
3. Try executing your function again.

该功能似乎工作正常(尽管由于没有表 'ATTENDANCE' 我无法运行完整测试)

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-13
    相关资源
    最近更新 更多