Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operand data type date is invalid for subtract operator

I have a field in my table called [LastDate] with DataType Date. and I am going to write a function which compute the [LastDate]-@PassedParameter, but the error happen :

Operand data type date is invalid for subtract operator.

I don't know why?

hara is the function:

CREATE FUNCTION Salman( @Date  date )
RETURNS TABLE 
AS
RETURN 
(

SELECT TOP 1000 [ID]
      ,[Name]
      ,[LastDate]
      ,[Rule]
      ,[CoA]
  FROM [Scheduling_Employee].[dbo].[Group]
  where ([LastDate]-@Date)%[Rule]=0  
)
GO
like image 859
Kam Par Avatar asked Aug 22 '14 15:08

Kam Par


1 Answers

You may try using the DATEDIFF function.

DATEDIFF ( datepart , startdate , enddate )

So in your case you may change like this:

where DATEDIFF(dd,LastDate,@Date)%[Rule]=0
               ^^--Change this to mm,qq whatever you want.
like image 107
Rahul Tripathi Avatar answered Oct 27 '22 02:10

Rahul Tripathi