Everything Works BUT...

  • I'm building a scalar function to return a float representing the percentage of 'alikeness' between to strings. When I output the concatenated string of variables is shows everything working as expected BUT the division between @Match and @Width always returns a 0.0. All other variables are correct. I'm apparently missing the boat of something easy here. Could someone please help me out?

    SNIPPET ------

    SET @SimilarBy = @Match / @Width

    SET @OUTPUTSTRING = '@Width ' + CONVERT(varchar(10), @Width)

    + ', @Match ' + CONVERT(varchar(20), @Match)

    + ', @NoMatch ' + CONVERT(varchar(20), @NoMatch)

    + ', @matches ' + CONVERT(varchar(20), @matches)

    + ', @SimilarBy ' + CONVERT(varchar(20), @SimilarBy)

    SQL Analyser Output

    @Width 12, @Match 8, @NoMatch 4, @matches 110111111000, @SimilarBy 0

    The 'SET @SimilarBy = @Match / @Width' apparently fails.

  • What is the type of the variables? If you're using integers, your division is an integer division, truncating the fractional part.

    Check the division operator in BOL for more info.

  • @SimilarBy is a float and the others are ints. You caught me. Thanks! I said it was probably something easy I overlooked.

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

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