If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > to get the max value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-04, 00:43
diya diya is offline
Registered User
 
Join Date: Feb 2004
Posts: 4
to get the max value

hi i have a ID column of varchar(10).

I store values in the format say 1001/04-05. In this the number left to the slash / represents just a slno that should be incremented for each record. and the nos to the right of slash represent the year 04-05

from this column i want to get the max slno.leaving the yr.

i can get the left side sl no but don't know how to get the max of them.
i used

Select left(id,4) from table1.
pls help
thanks
Reply With Quote
  #2 (permalink)  
Old 02-21-04, 01:31
msazeezjuly msazeezjuly is offline
Registered User
 
Join Date: Feb 2004
Location: Chennai, INDIA
Posts: 3
Re: to get the max value

Quote:
Originally posted by diya
hi i have a ID column of varchar(10).

I store values in the format say 1001/04-05. In this the number left to the slash / represents just a slno that should be incremented for each record. and the nos to the right of slash represent the year 04-05

from this column i want to get the max slno.leaving the yr.

i can get the left side sl no but don't know how to get the max of them.
i used

Select left(id,4) from table1.
pls help
thanks
Hi,

I don't understand how do you store the value, i have tried but shows some other value.

SQL> create table sereal(slno varchar(20));

Table created.

SQL> insert into sereal values(1000/04-05);

1 row created.

SQL> insert into sereal values(1001/04-05);

1 row created.

SQL> select * from sereal;

SLNO
--------------------
245
245.25

SQL>


Regards
Syed
Reply With Quote
  #3 (permalink)  
Old 02-21-04, 07:38
r123456 r123456 is offline
Registered User
 
Join Date: Sep 2003
Location: The extremely Royal borough of Kensington, London
Posts: 778
I strongly recommend redesigning your table to be in first normal form.

To obtain the solution for your current table structure,

Oracle 9i:
Select MAX(SUBSTR(id, 1, 4)) from table;

SQL Server 2000:
Select MAX(LEFT(id, 4)) from table;
__________________
Bessie Braddock: Winston, you are drunk!
Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.
Reply With Quote
  #4 (permalink)  
Old 02-27-04, 06:46
praveenpr praveenpr is offline
Registered User
 
Join Date: Jan 2004
Location: Singapore
Posts: 89
Re: to get the max value

Hi Diya,
It seems that you slno may keep increasing day by day.
So use MAX, INSTR and SUBTSR function. This will help you
to meet your requirement.

Thanx
praveenpr@rediffmail.com
Praveen

Quote:
Originally posted by diya
hi i have a ID column of varchar(10).

I store values in the format say 1001/04-05. In this the number left to the slash / represents just a slno that should be incremented for each record. and the nos to the right of slash represent the year 04-05

from this column i want to get the max slno.leaving the yr.

i can get the left side sl no but don't know how to get the max of them.
i used

Select left(id,4) from table1.
pls help
thanks
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

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