Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2005
    Location
    Fife, Scotland
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    SQLServer UPDATE - Concatenation

    Hi, I have a field in an SQLServer database, and I need to add a string to the end of the existing content. Is it possible to do this in a single UPDATE query?

    I guess it would be possible using a sub-query, such as:

    Code:
    UPDATE table SET column='(SELECT column FROM table WHERE columnID=ID)"&newString&"' WHERE columnID=ID
    but Im keen to know if I can do it with a single query...
    COYS!

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Concatenate the column onto itself with the added text:
    Code:
    UPDATE table SET column = column + ' some value'
    Good luck.

  • #3
    New Coder
    Join Date
    Jul 2005
    Location
    Fife, Scotland
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks for the reply brandoe.

    Your theory was correct, only a slight alteration was required to avoid a data type error (data types text and varchar are incompatible in the add operator).

    This is the working code:

    Code:
    UPDATE table SET column=Convert(VarChar(80),column) + Convert(VarChar(80),'"&some value&"')
    COYS!

  • #4
    New Coder
    Join Date
    Jul 2005
    Location
    Fife, Scotland
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    if anyone else is having a similar issue with data type concatenation, heres a link to the solution that worked for me.

    http://www.thescripts.com/forum/thread570278.html

    COYS!


  •  

    Posting Permissions

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