How do I fix this error?

  • When I insert the following into my query...I get an error

    ,max(case when patins.rank = 1.0 then CLAIMS.[TOTALPAID] else '' end)

    TotalPaid is a field that contains, for example, 445.45

    The message I receive is 'Error converting data type varchar to numeric'

    but, this case statement works:

    ,max(case when patins.rank = 1.0 then INSCOMP.ORG else '' end)

    Inscomp.Org just gives the insurance company

  • cory.bullard76 (8/17/2015)


    When I insert the following into my query...I get an error

    ,max(case when patins.rank = 1.0 then CLAIMS.[TOTALPAID] else '' end)

    TotalPaid is a field that contains, for example, 445.45

    The message I receive is 'Error converting data type varchar to numeric'

    but, this case statement works:

    ,max(case when patins.rank = 1.0 then INSCOMP.ORG else '' end)

    Inscomp.Org just gives the insurance company

    Quick suggestion, change

    ,max(case when patins.rank = 1.0 then CLAIMS.[TOTALPAID] else '' end)

    to this

    ,max(case when patins.rank = 1.0 then CLAIMS.[TOTALPAID] else 0 end)

    😎

  • Wow, that was easy.. haha....thanks!

  • cory.bullard76 (8/17/2015)


    When I insert the following into my query...I get an error

    ,max(case when patins.rank = 1.0 then CLAIMS.[TOTALPAID] else '' end)

    TotalPaid is a field that contains, for example, 445.45

    The message I receive is 'Error converting data type varchar to numeric'

    but, this case statement works:

    ,max(case when patins.rank = 1.0 then INSCOMP.ORG else '' end)

    Inscomp.Org just gives the insurance company

    CLAIMS.[TOTALPAID] is defined as a numeric data type so when using CASE SQL Server expects to output a numeric and '' is a varchar value that can't be converted to a numeric. I would change the '' to NULL because it won't be returned as the MAX.

    Edit: Missed Eirikur's post. I wouldn't do 0 unless you are sure the MAX for valid TOTALPAID's will be > 0. Otherwise you will get an invalid max.

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

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