ALTER Function dbo.DynamicDateDiff
(@Interval VarChar(2),
@Date1 DateTime,
@Date2 DateTime)
Returns Int
As
Begin
Return (Select Case @Interval
When 'w' Then DateDiff(WEEK, @Date1, @Date2)
When 'y' Then DateDiff(YEAR, @Date1, @Date2)
When 'd' Then DateDiff(DAY, @Date1, @Date2)
When 'm' Then DateDiff(MONTH , @Date1, @Date2)
End
)
End
select a.Item
, (SELECT DBO.DynamicDateDiff(''d'',A.TglJatuhTempo, ''' + @ToDate + ''')) AS HariJatuhTempo
from ItemMaster a
I try below code.
select TOP 1 NomorFkt, tglfkt
, (SELECT DBO.DynamicDateDiff('d', A.TglJatuhTempo, '20190221')) AS HariJatuhTempo
from THINVSELL a
NomorFkt tglfkt HariJatuhTempo
--------------------------
NRJ-AU-2019-02-0024 2019-02-21 00:00:00.000 -90
(1 row(s) affected)
Why the result is minus 90 ?
Thank you.