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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With