Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all...........

thanks n advance......

In my table i have a column with value of nvarchar data type value like 'A1','A2','A3' simultanously incremented.....

my need is how to get the max from that column value.......
(eg)
colname
A1
A2
A3
A4
A11
A12
A13

i have the value likethis i have to get the max value as A12 instead am getting the value as A4 is max...


i use the query as

select max(colname) from the table....

what i have to do to get my max value as A13.

pls guide me....


thanks in advance...
with warm regards.......
Cva.......
Posted

If number of alphabets in the column is fixed then you can use this query

select max(substring(columnname,2(no.of alphabets+1),len(columnname)-1)) from tablename


with this query you will get max integer that means 13
and in code while inserting into database you can attach that fixed alphabet to the column and then insert.

I hope you understood what i am saying.
if i am not clear feel free to ask.
 
Share this answer
 
v4
Comments
MemberCva 28-Sep-11 0:37am    
thanks yar....
while executing my query igot he result incorrect syntax near '('.....
my query is
select MAX ( substring (ID,2(2+1),len(ID)-1) ) from Table1

2+1 here 2 mentions the no of alphabets am using in that column, AB is my alphabet in that column.....

thanks in advance.....

with warm regards....
Cva.....
Check this out

SQL
select max(convert(int,replace(a,'A',''))) from
(select 'A1' a
union all select 'A2'
union all select 'A3'
union all select 'A4'
union all select 'A11'
union all select 'A12'
union all select 'A13') tmpTable
 
Share this answer
 
Comments
MemberCva 28-Sep-11 0:32am    
thanks sachin....

i got the result by ur query but my need is to get the result dynamically.....

thanks in advance.....
with warm regards...
Cva....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900