MS SQL Update Query

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 2
Reputation: Wakhal is an unknown quantity at this point 
Solved Threads: 0
Wakhal Wakhal is offline Offline
Newbie Poster

MS SQL Update Query

 
0
  #1
Apr 23rd, 2008
Suppose a table ABC have column XYZ containing data

3PSY0001-06-08-F
3PSY0001A-07-09-P
3PSY0001-02-09-P
3PSY0001-07-07-F
3PSY0002-09-08-P
3PSY0002A-01-03-P
3PSY0002-07-07-F

How can i write a query so that the data ending with P without A can be updated with A.

For example, with that query, data

3PSY0001-02-09-P AND 3PSY0002-09-08-P will be updated as

3PSY0001A-02-09-P AND 3PSY0002A-09-08-P while the other data remains the same.

Please Help.

Warm Regards
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 42
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 13
huangzhi huangzhi is offline Offline
Light Poster

Re: MS SQL Update Query

 
0
  #2
Apr 23rd, 2008
  1. UPDATE ABC
  2. SET XYZ = LEFT(XYZ, 8) + 'A' + substring(XYZ, 9, 1000)
  3. WHERE XYZ LIKE '%P' AND XYZ NOT LIKE '%A%'
Last edited by huangzhi; Apr 23rd, 2008 at 10:33 am.
Hence Wijaya
www.ex-Soft.tk
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: Wakhal is an unknown quantity at this point 
Solved Threads: 0
Wakhal Wakhal is offline Offline
Newbie Poster

Re: MS SQL Update Query

 
0
  #3
Apr 23rd, 2008
Hi Huangzhi,

Works like a charm. You are a life saver. Thanks a lot.

Warm Regards
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC