Go Back   CodingForums.com > :: Server side development > MySQL > Other Databases

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-08-2006, 10:27 AM   PM User | #1
tom123
Regular Coder

 
Join Date: Apr 2005
Location: Ireland
Posts: 122
Thanks: 4
Thanked 0 Times in 0 Posts
tom123 is an unknown quantity at this point
Oracle: extract part of field and create next id

Hi guys,

I need to extract all fields that begin with "AW", there are numbers after this i.e AW11, AW12.....

Next i need to find the largert number i.e 12 in this case. So far i have

Code:
my $product_query = qq(SELECT code,
                         FROM product
                         WHERE code LIKE 'AW%');
Thanks in advance
tom123 is offline   Reply With Quote
Old 08-11-2006, 08:14 PM   PM User | #2
arnyinc
Regular Coder

 
Join Date: Jan 2003
Posts: 867
Thanks: 4
Thanked 8 Times in 8 Posts
arnyinc is an unknown quantity at this point
This will chop off the first two characters and select the highest number.

select max(to_number(substr(CODE, 3, length(code)-2))) from product

However, I would recommend storing just the number and prepending "AW" to it when you need to print the number out.
arnyinc is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 AM.


Advertisement
Log in to turn off these ads.