Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select max(LACode) as M from dbo.tblLeaveApproval where len(LACode)=8


The query results :

LAC-8038


But If I write the query like :

SQL
select max(LACode) as M from dbo.tblLeaveApproval 


then it results :

LAC-999


Please give me a solution of this problem. Why such kind of difference is occurs?
Posted
Updated 30-Oct-13 23:24pm
v2

The data in the LACode column is being evaluated as a string hence LAC-9... is bigger than LAC-8... and when you filter on the length then you will not see the LAC-9xx values hence LAC-8xxx will be the bigger value.
 
Share this answer
 
Comments
CPallini 31-Oct-13 6:14am    
5.
Mehdi Gholam 31-Oct-13 6:16am    
Thanks!
SQL
select MAX(CAST(SUBSTR(LACode,5) as integer)) from dbo.tblLeaveApproval;


returns the maximum number after the 'LAC-' prefix.
 
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