Results 1 to 8 of 8
  1. #1
    Join Date
    May 2008
    Posts
    4

    Unanswered: concatenate (possibly) in Interactive SQL

    Field name: alternate_id
    Table name: basic
    A client stores id numbers in the alternate_id field. Some of the id numbers are preceded by 'KW', while others are not. My goal is to write a script in Interactive SQL that will insert 'KW' before the id numbers that do not already contain 'KW'. I am not sure how to write this script. I thought it would be a concatenate, but I don't think so now. Can someone please point me in the right direction? Thank you!

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Use an UPDATE statement which SETs the value of alternative_id to concatenate 'KW' + alternative_id WHERE alternate_id is NOT LIKE 'KW%' already (where % is a wildcard).
    George
    Home | Blog

  3. #3
    Join Date
    May 2008
    Posts
    4

    concatenate statement

    I tried the following two statements, but receive an error "syntax error near kw"

    update basic set alternate_id = concatenate 'KW' + alternate_id where alternate_id is not like 'KW%'

    update basic set alternate_id = concatenate 'KW' + alternate_id where alternate_id <> 'KW%'

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    which DBMS are you using?

    i googled for "Interactive SQL" and came up with this which is DB2, and this which is Sybase
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    May 2008
    Posts
    4

    concatenate

    I am using Sybase SQL

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    okay, moving thread to Sybase forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try this --
    Code:
    UPDATE basic 
       SET alternate_id = 'KW' + alternate_id 
     WHERE alternate_id NOT LIKE 'KW%'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    May 2008
    Posts
    4

    not concatenate

    That worked! It wasn't a concatenate statement after all. Thank you so much for your prompt assistance!! I appreciate your help!

Posting Permissions

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