Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have a VARCHAR field in DB naming Userid

The value in it like DDP-1,DDP-2,DDP-3 etc

i want to select max from that using SQL QUERY

ie;

from

DDP-1
DDP-2
DDP-3

i need to get 3 from above list as max of that field,

please help me if there is anyway to do it
Posted
Comments
Sunasara Imdadhusen 17-Feb-11 1:04am    
You need to get only 3 or DDP-3?
Sandeep Mewara 17-Feb-11 1:05am    
You have to use functions, split the value and then get it!

Hi Kishore,

i assume you want only Number. Here is solution

SQL
SELECT REPLACE(MAX(departmentid),'DDP-','') FROM department


Thanks,
Imdadhusen
 
Share this answer
 
Comments
Sunasara Imdadhusen 17-Feb-11 1:16am    
This will return only 3
Hope Max()[^] will give you an idea.
 
Share this answer
 
select top(1) userid from tablename order by userid desc
 
Share this answer
 

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