right string function and convert

  • Why does the following TSQL produce different results ?

    Query

    select right('00000000'+ convert(char(8),123),8)

    Results

    --------

    123

    Query

    select right('00000000'+ convert(varchar(8),123),8)

    Results

    --------

    00000123

    When I ran the sql using SQL6.5, both produced 00000123 !

    TIA

  • The CONVERT function from integer to char right pads the resulting string with spaces.

    The conversion to varchar doesn't do this, since it stores only the 'meaningful' characters.

    Why did it work in 6.5? Maybe the RIGHT function stripped the trailing spaces automatically?

  • Have a look at ANSI_PADDING

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

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