Results 1 to 3 of 3

Thread: tsql: how to concatenate 2#'s--not add?

  1. #1
    Join Date
    May 2005
    Posts
    111

    tsql: how to concatenate 2#'s--not add?

    trying to concatenate a varchar field containing numbers with the number 1. i tried casting to text and received an error. and if I simply use '1' + fieldname --sql adds the numbers together.

    update phonebook_patient_rooms
    set extension = cast('1' as text) + cast(extension as text)
    --set extension = '1' + extension
    where len(extension) < 5
    and extension like '[0-9]%'
    and extension = '4967'

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    cast to char instead of text. if the number is fixed width then use char(n) otherwise you need to RTRIM to remove blank space between two expressions.

    update phonebook_patient_rooms
    set extension = cast('1' as char) + cast(extension as char)
    --set extension = '1' + extension
    where len(extension) < 5
    and extension like '[0-9]&#37;'
    and extension = '4967'

  3. #3
    Join Date
    May 2005
    Posts
    111
    Thank You!

Posting Permissions

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