Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    1

    Question Unanswered: Concating text columns

    I have a table with a text column
    I want to select that column and add some text to the result
    e.g.
    select textcolumn + 'Added Text' From xTable

    but this fails because one can not use + or concat on text columns
    i get around this by using cast as varchar(1024)
    e.g.
    select cast(textcolumn as varchar(1024)) + 'Added Text' From xTable

    but this would cut the text column after 1024 chars

    is there a way around this and not limiting the length of the text column

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    I'm at home and not a work at the moment so I can't check for sure (or rather I'm not going to), but can't you omit the length of the varchar in the cast statement??

  3. #3
    Join Date
    Nov 2003
    Posts
    48
    select cast(textcolumn as varchar) + 'Added Text' From xTable
    or
    select convert(varchar, textcolumn) + 'Added Text' From xTable

    works for my SQL2000, otherwise, you can just trim out the trailing spaces
    Shianmiin

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    149
    Just be aware that the max length of varchar is 8000.

    Originally posted by shianmiin
    select cast(textcolumn as varchar) + 'Added Text' From xTable
    or
    select convert(varchar, textcolumn) + 'Added Text' From xTable

    works for my SQL2000, otherwise, you can just trim out the trailing spaces

Posting Permissions

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