This stored procedure works great as long as the values in the UpTime1 and DownTime1 are in a valid time format HH:MM. If the're not, it fails to return anything. The DateDiff statement is calculating the number of minutes and this is the line that gives me a hard time if there is any bad data. Those fields are a varchar(5).
We are working on getting the front-end corrected to prevent that, but if I can find a way to make the stored procedure return a zero for the datediff if the times are invalid would solve the immediate problem.
Thanks for help help.
SELECT *,datepart(hh,RecDateTime)*60+datepart(mi,RecDateTime) as iStartTime,convert(varchar(10),RecDateTime,110) as justdate,
DATEDIFF( minute, CAST(UpTime1 AS datetime), CAST(DownTime1 AS datetime)) as TotalTimeUp1
from dbo.co_Pat_Tourniquet (nolock)
WHERE meetingnumber=@meetingnumber and noteID=@noteID and isactive=1
ORDER BY recDateTime Desc
Kirk