SQL Server Performance

Wierd convert problem

Discussion in 'General Developer Questions' started by krypto, Aug 19, 2003.

  1. krypto New Member

    We are converting a char to numeric (so we can do a sort) and the values being returned are wrong. Most of the time they are fine as in the first example.

    Here's the syntax:

    This one is fine:

    select convert(int,(convert(varbinary(10),rtrim('2003-189807')))) --returns 943274032
    select convert(int,(convert(varbinary(10),rtrim('2003-190047')))) --returns 959459380


    This one is wacky:

    select convert(int,(convert(varbinary(20),rtrim('2003-189807')))) --returns 959983671
    select convert(int,(convert(varbinary(20),rtrim('2003-190047')))) --returns 808465463

    Why would the bottom one line return a value that's lower (then the first example) , when the number we are passing it is higher?

    Any help or suggesions GREATLY appreciated.
  2. bambola New Member

    Here is your answer

    select convert(varbinary(20),rtrim('2003-189807')), datalength(convert(varbinary(20),rtrim('2003-189807')))
    select convert(varbinary(20),rtrim('2003-190047')), datalength(convert(varbinary(20),rtrim('2003-190047')))

    select convert(varbinary, 959983671), datalength(convert(varbinary, 959983671))
    select convert(varbinary, 808465463), datalength(convert(varbinary, 808465463))

    Bambola.

Share This Page