RIGHT function error

  • Hi everyone,

    PLease see the snippet below: this is a dataset from my ssrs report. Wonder, whats missing here as it ran fine before. thanks

    Msg 536, Level 16, State 2, Line 2

    Invalid length parameter passed to the RIGHT function.

    select distinct DETAIL =(case when DETAIL is not null then

    Ltrim (stuff(right(DETAIL, CHARINDEX(':', DETAIL,2) - 1), 1, 1, ' '))

    else 'Other' end) from PRODUCT

  • Look the return value of charindex. I Think you don't have a':' for the "detail" column. If is the case charindex return 0 -1 = -1 Invalid value.

  • select right('Test OutPut',charindex(':','Test:123',2)-1)

    go

    select right('Test OutPut',charindex(':','Test123',2)-1)

    go

    The second query gave you an Error because don't find ':' and get -1

  • select

    case when charindex(':','Test123',2) = 0 then 'Test OutPut'

    else

    right('Test OutPut',charindex(':','Test:123',2)-1)

    end

Viewing 4 posts - 1 through 3 (of 3 total)

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