Search code examples
sqlsql-serversql-server-2016

Type conversion in expression may affect cardinality estimate in query plan


I have a warning in my Execution plan that I can not get rid of. I've made an Minimal, Reproducible Example here:

declare @TestData Table
(
  FloatValue float null
)

insert into @TestData values
 (null), (0.1)

select 
    CONVERT(varchar, FloatValue * 100.00) + ' pct.' PctValue
from 
    @TestData

I've included the warning.

enter image description here


Solution

  • You can change CONVERT(varchar, FloatValue * 100.00) to FORMAT(FloatValue * 100.00, 'N0') in the query:

    declare @TestData Table
    (
      FloatValue float null
    )
    
    insert into @TestData values
     (null), (0.1)
    
    select 
        FORMAT(FloatValue * 100.00, 'N0') + ' pct.' PctValue
    from 
        @TestData
    

    And it will get rid of the warning:

    The warning 'Type conversion in expression may affect cardinality estimate in query plan' is now gone from the message box