How to preserve trailing spaces

  • Ken Simmons (5/15/2009)


    I was thinking the same thing as Florian.

    Something like...

    MainTable

    MainTableID

    OtherFieilds

    MainTableDscr

    MainTableID

    DscrID

    DscrTable

    DscrID

    That's a similar approach to the one I wanted to take. Unfortunately I have no choice in the matter.

    DscrSequence

    Dscr

  • RBarryYoung (5/15/2009)


    Florian Reischl (5/15/2009)


    RBarryYoung (5/15/2009)


    FelixG (5/15/2009)


    Vrachar type removes trailing spaces... you must use the CHAR type

    It doesn't seem to be doing that on my system:

    --========

    declare @s-2 varchar(30)

    declare @t varchar(30)

    set @s-2 = 'K '

    Select @t = @s-2

    select datalength(@s), datalength(@t)

    Declare @D as table (st varchar(30))

    INSERT into @D Select @s-2

    INSERT into @D Select @t

    SELECT st, datalength(st) From @D

    :pinch:

    Thanks Barry for showing me the wood between the trees!!

    I still think there is a normalization problem.

    Agreed.

    As to the "Varchars trim spaces" belief, I suspect that it got it's start from the fact that the LEN(..) function in fact, does not count trailing spaces (that's why I had to use the DATALENGTH() function).

    Thanks for clarifying that for me.

  • Sorry. Did not read the complete post. I´ve deleted my answer.

  • FelixG (5/15/2009)


    If all you wanna do is to have a 300 char field containing all the 10 description fields from the legacy table... you just have to do this:

    Insert last_table set description300= description1+replicate(' ',30-len(description1)) +description2+replicate(' ',30-len(description2)) +.....+description10 from legacy_table

    However... your scenario is kinda strange .... you should take a deeper look on your design...

    I want to thank everyone for the help. This approach did the trick.

Viewing 4 posts - 16 through 18 (of 18 total)

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