Msg 241, Level 16, State 1, Line 1

  • 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 (

    SELECTStackTrace

    FROM[EventLog]

    WHERE[EventTypeID] = 80

    AND [LoggedDateTime] >= @StartDay

    AND [LoggedDateTime] < @EndDay

    UNION ALL

    SELECTStackTrace

    FROM[TempArchive].[dbo].[EventLog]

    WHERE[EventTypeID] = 80

    AND [LoggedDateTime] >= @StartDay

    AND [LoggedDateTime] < @EndDay

    )AS T

    RETURN (@MaxLatency)

    END

  • Looks like LoggedDateTime is not a datetime column.

    Can you post the create script for the tables involved?

    -- Gianluca Sartori

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply