I have a stored procedure that pulls data from 2 different on 2 different servers as follows:
SELECT
LocalDB.Record_ID,
LocalDB.Total/1440 as TotalTime,
((REMOTE_ACTIVE.Time_Adjusted) - (REMOTE_ACTIVETimes.CALCTimeSec)) as TimeLeft,
LocalDB.isManualEntry
FROM LocalDatabase.dbo.Records LocalDB left join
[RemoteServer].[Reporting].[dbo].[ActiveWO] REMOTE_ACTIVE ON
LocalDB.WO_ID = REMOTE_ACTIVE.[PO_ID]
left join [RemoteServer].[Reporting].[dbo].[ActiveWOTimes] REMOTE_ACTIVETimes ON
LocalDB.WO_ID = REMOTE_ACTIVETimes.[PO_ID]
What can happen is that sometimes the "TimeLeft" value can be 0. When that happens I want to replace that value with something like
IF(TimeLeft is 0 or null)
(getdate() - LocalDB.CreatedDate) as TimeElapsed
The thing is, I'm not sure how to implement such an IF statement or if it is even possible.