sql server - DateDiff returns negative value in sql -
i doing calculation in sql query using datediff
function. calculation went wrong if datediff
value came in negative
declare @actualtime numeric(10,2)=677.00 select convert(numeric(10,2),(100*((@actualtime-(convert(numeric(10,2),convert(varchar(10),sum(datediff(minute,vendorticketraisedon ,closedon)) / 60)+'.'+ right('00'+convert(varchar(2),sum(datediff(minute, vendorticketraisedon , closedon)) % 60),2))))/@actualtime*1)))[ags uptime %] ticket
two columns vendorticketraisedon
& closedon
of type datetime
. if closedon
> vendorticketraisedon
value came in negetive.
how treat case produce result 0 ?
if value in negative datediff should give output 0 instead of -value
db : sql server 2008
query:
declare @actualtime numeric(10,2)=677.00 select case when closedon > vendorticketraisedon 0 else convert(numeric(10,2),(100*((@actualtime-(convert(numeric(10,2),convert(varchar(10),sum(datediff(minute,vendorticketraisedon ,closedon)) / 60)+'.'+ right('00'+convert(varchar(2),sum(datediff(minute, vendorticketraisedon , closedon)) % 60),2))))/@actualtime*1))) end [ags uptime %] ticket
Comments
Post a Comment