Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2006
    Location
    Czech Republic
    Posts
    82

    Unanswered: How to save trailing blanks?

    Hello,

    could someone help me with this? If I save strings, trailing blanks are truncated and following code don´t give the same result

    Code:
    drop table d_test
    go
    create table d_test ( text varchar(20) )
    go
    declare @ln_x varchar(20)
    select @ln_x = "                 "
    select "START" + @ln_x + "END"
    insert d_test values (@ln_x)
    select @ln_x = text from d_test
    select "START" + @ln_x + "END"
    
    RESULT:
    
                                 
    -                            
    START                 END                 
    
                                 
    -                            
    START END
    Last edited by Musil David; 10-18-06 at 10:45.

  2. #2
    Join Date
    Oct 2006
    Posts
    4
    Use CHAR not VARCHAR

  3. #3
    Join Date
    Sep 2006
    Location
    Czech Republic
    Posts
    82
    But i want to save different lenght of spaces in the table d_test. If I use e.g. char(20) ia can save ever just twenty blanks....

  4. #4
    Join Date
    Oct 2006
    Posts
    4
    Varchar VARIABLES don't trim trailing blanks but Varchar COLUMNS do trim the trailing blanks. To do what you need to do you need to have another column that specifies the length of the data and pad out to this value when you select.

    Code:
    drop table d_test
    go
    create table d_test ( txt varchar(20), len int )
    go
    declare @ln_x varchar(20)
    select @ln_x = "                 "
    select "START" + @ln_x + "END"
    insert d_test values (@ln_x,char_length(@ln_x))
    select @ln_x = txt + space(len - char_Length(txt)) from d_test
    select "START" + @ln_x + "END"
    Last edited by wildthing; 10-18-06 at 11:22.

  5. #5
    Join Date
    Sep 2006
    Location
    Czech Republic
    Posts
    82
    Thanks for reply. But situation is little complicated, Ive found that there can be chars in string with blanks

    Code:
    declare @ln_x varchar(20)
    select @ln_x = " X      Y      Z     "
    There is no easy way how not lose trailing blanks????

  6. #6
    Join Date
    Jan 2003
    Location
    Geneva, Switzerland
    Posts
    353
    As far as Sybase is concerned the trailing blanks are not significant. If you need to structure the data in a column in a particular way then you might consider a different table structure to handle this. In any case getting Sybase to keep track of varying lengths of trailing blanks is going to be a bit of a hack...

    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •