2017-08-13 62 views
0

我創建了一個功能,現在相當傳遞靜態值我想在函數中添加參數,但調用函數後它開始拋出一個錯誤:多個參數錯誤,而在SQL Server中創建功能

Procedure or function dbo.hello has too many arguments specified.

功能:

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'); 

錯誤:

Procedure or function dbo.hello has too many arguments specified

+0

我不能瑞普這個問題,功能工作正常。你是否對正確的服務器和數據庫運行select語句? –

+0

'select * from sys.objects where name ='hello'','sp_helptext'dbo.hello'' –

回答

0

可能您首次創建的函數只有一個參數。 然後對「創建函數」腳本進行更改,並忘記部署?

我會;

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

功能似乎正常工作(雖然我不能運行完整測試,由於沒有表「出勤」)