在SQL Server中创建函数时出现多个参数错误

时间:2017-08-13 11:32:13

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

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

  

程序或函数dbo.hello指定了太多参数。

功能:

private MyDBContext() : base(@"Data Source=(LocalDB)\v11.0;Initial Catalog=DB;Integrated Security=True")

调用该函数:

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

错误:

  

程序或函数dbo.hello指定了太多参数

1 个答案:

答案 0 :(得分:0)

可能你首先用一个参数创建了这个函数。 然后对“创建功能”进行了更改。脚本,忘了部署?

我愿意;

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

该功能似乎工作正常(虽然由于没有桌子而无法进行全面测试&#39; ATTENDANCE&#39;)