dbTalk Databases Forums  

update partial string

comp.databases.sybase comp.databases.sybase


Discuss update partial string in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
eddie wang
 
Posts: n/a

Default update partial string - 08-02-2004 , 02:52 PM






Hi,
I need to update the phone numbers in a table. if the first 7 numbers
are "(909)222-", I need to change them to "(909)333-", regardless what
the last 4 numbers are.

I can select the records easily:
select phone from employee
where phone like "(909)222-%'

but how do I update all the records in one T-SQL statement? I don't
think I can use % in my update statement?

Thank you in advance.

Reply With Quote
  #2  
Old   
Brian Keener
 
Posts: n/a

Default Re: update partial string - 08-02-2004 , 03:51 PM






Eddie wang wrote:
Quote:
I can select the records easily:
select phone from employee
where phone like "(909)222-%'

but how do I update all the records in one T-SQL statement? I don't
think I can use % in my update statement?

update employee set substring(phone,6,3)='333' where phone like "(909)222-%'

or

update employee set substring(phone,locate(phone,'222-'),3)='333' where phone
like "(909)222-%'

bk



Reply With Quote
  #3  
Old   
Willie Kraatz
 
Posts: n/a

Default Re: update partial string - 08-03-2004 , 01:38 PM



update employee set phone = substring(phone,1,5) + '333' + substring(phone,
9, 5) where phone like "(909)222%"

"eddie wang" <eddiekwang (AT) hotmail (DOT) com> wrote

Quote:
Hi,
I need to update the phone numbers in a table. if the first 7 numbers
are "(909)222-", I need to change them to "(909)333-", regardless what
the last 4 numbers are.

I can select the records easily:
select phone from employee
where phone like "(909)222-%'

but how do I update all the records in one T-SQL statement? I don't
think I can use % in my update statement?

Thank you in advance.



Reply With Quote
  #4  
Old   
eddie wang
 
Posts: n/a

Default Re: update partial string - 08-03-2004 , 04:08 PM



Brian,
Thank you for the reply! I didn't know about the "substring" funtion.
It is useful to know.

I ended up using "replace". (I completely forgot about "replace" when
I posted my message).

Thanks again

Brian Keener <bkeener (AT) thesoftwaresource (DOT) com> wrote

Quote:
Eddie wang wrote:
I can select the records easily:
select phone from employee
where phone like "(909)222-%'

but how do I update all the records in one T-SQL statement? I don't
think I can use % in my update statement?

update employee set substring(phone,6,3)='333' where phone like "(909)222-%'

or

update employee set substring(phone,locate(phone,'222-'),3)='333' where phone
like "(909)222-%'

bk

Reply With Quote
Reply




Thread Tools
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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.