Operand data type date is invalid for subtract operator
16,263
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.
Author by
Kam Par
Updated on June 13, 2022Comments
-
Kam Par almost 2 years
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