white spaces being filled in char(N) type field

  • Hi,

    I have defined a column of data type is char(15). But I noticed that if I insert a record where the data for this column is smaller than 15 in length, blank spaces are filled in. This causes problem while taking joins.

    Why blank spaces are filled in this column to make its length 15?

    I am using MS SQL server 2000.

    Thanks and Regards,

    Unnic

  • That's because you use CHAR instead of VARCHAR. CHAR is fixed length no matter how many characters you actually entered.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • if you must use char and the spaces are giving you grief, you can use a "rtrim" function:

    select rtrim(cast('1' as char(5)))

    Signature is NULL

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

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