Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with query when there is bad data
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Help with query when there is bad data
Environment versions
SQL Server:
SQL Server 2000
Application:
Desktop
Miscellaneous
Thread ID:
01407429
Message ID:
01407429
Views:
89
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
Next
Reply
Map
View

Click here to load this message in the networking platform