Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003
    Posts
    64

    Question Unanswered: Appending text-fields with UPDATE...

    Hi!

    The following simple UPDATE reports a number of lines updated, but none of the fields show any actual changes...
    Code:
    CREATE TABLE #Meow (comment CHAR(32))
    INSERT INTO #Meow (comment) VALUES ('Woof')
    UPDATE #Meow SET comment = comment || 'Meow'
    SELECT * FROM #Meow
    go
    (1 row affected)
    (1 row affected)
     comment                         
     --------------------------------
     Woof
    Why would this be? Prepending in the same manner works fine:
    Code:
    UPDATE #Meow SET comment = 'Meow' || comment
    SELECT * FROM #Meow
    go
    (1 row affected)
    (1 row affected)
     comment                         
     --------------------------------
     MeowWoof
    What's wrong? Thanks!
    If you ever back up Sybase, you want this backup-server plugin.

  2. #2
    Join Date
    Apr 2003
    Posts
    64
    Ok, never mind. Solved here by a more experienced co-worker... Because the field is of type CHAR it is padded with blanks (a rather foolish SQL-legacy, IMHO). So the string gets appended after the blanks, and is then chopped off to fit the width of the field...

    The work-around is to either use VARCHAR or append the suffix to trim the existing value before appending it:

    Code:
    UPDATE #Meow SET comment = rtrim(comment) || 'Meow'
    If you ever back up Sybase, you want this backup-server plugin.

Posting Permissions

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