Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    3

    Unanswered: Appending a Field

    I know this must be simple, but I am stumpped, please help!

    I am writing a stored procedure in SQL 2000 where an incomming variable is a string of characters (a couple of sentences) and I want to add that to the existing string of characters in a table field called "Comments".

    I do not know how to append the text in a field. How is that best done?

    The basic function of the procedure is to take whatever string is passed to it and append it to the current contents of the field "Comments". As the procedure is ran over and over again, the field is constantly appended with the incomming text.

    What is the best way to do this? Can anyone give me an example?

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    update tablename set fieldname = fieldname + @incomingtext where condition ...
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    May 2003
    Posts
    26
    Also, if you haven't already, you may want to look at the data type of the "comments" field and make sure when you are appending the next text the maximum length for that data type is not being exceeded.

  4. #4
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Originally posted by Donner
    Also, if you haven't already, you may want to look at the data type of the "comments" field and make sure when you are appending the next text the maximum length for that data type is not being exceeded.
    create table test(id int identity,code varchar(50))
    go
    insert test(code) values('a')
    go
    update test set code=code+'b' where datalength(code+'b')<51
    go
    select * from test

Posting Permissions

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