Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > concatenate (possibly) in Interactive SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-29-08, 18:59
marynivemo marynivemo is offline
Registered User
 
Join Date: May 2008
Posts: 4
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!
Reply With Quote
  #2 (permalink)  
Old 05-29-08, 19:39
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,131
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
You only stop learning when you stop asking questions.
Reply With Quote
  #3 (permalink)  
Old 05-29-08, 23:09
marynivemo marynivemo is offline
Registered User
 
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%'
Reply With Quote
  #4 (permalink)  
Old 05-29-08, 23:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
which DBMS are you using?

i googled for "Interactive SQL" and came up with this which is DB2, and this which is Sybase
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #5 (permalink)  
Old 05-30-08, 00:21
marynivemo marynivemo is offline
Registered User
 
Join Date: May 2008
Posts: 4
concatenate

I am using Sybase SQL
Reply With Quote
  #6 (permalink)  
Old 05-30-08, 00:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
okay, moving thread to Sybase forum
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #7 (permalink)  
Old 05-30-08, 00:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,537
try this --
Code:
UPDATE basic SET alternate_id = 'KW' + alternate_id WHERE alternate_id NOT LIKE 'KW%'
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #8 (permalink)  
Old 05-30-08, 01:01
marynivemo marynivemo is offline
Registered User
 
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On