getting this error when I run this function:
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
Any help is greatly appreciated.
ALTER FUNCTION [dbo].[f_WeeklyReport_MaxLatency_V1]
(
@StartDay DATETIME,
@EndDay DATETIME
)
RETURNS NUMERIC
AS
BEGIN
-- Declare the return variable
DECLARE @MaxLatency NUMERIC(6,2)
SELECT @MaxLatency = MAX(CONVERT(INT, CASE WHEN ISNUMERIC(StackTrace COLLATE DATABASE_DEFAULT )=1 THEN StackTrace END))
FROM (
SELECT StackTrace
FROM [EventLog]
WHERE [EventTypeID] = 80
AND [LoggedDateTime] >= @StartDay
AND [LoggedDateTime] < @EndDay
UNION ALL
SELECT StackTrace
FROM [TempArchive].[dbo].[EventLog]
WHERE [EventTypeID] = 80
AND [LoggedDateTime] >= @StartDay
AND [LoggedDateTime] < @EndDay
)AS T
RETURN (@MaxLatency)
END