0

There is an Issue while i try to auto Increment alphanumeric Id (or number Series) for example

in Mysql "Sample" Table 'RefNo' column (of type Varchar)

AB7 AB10 AB9 AB8

above i have four entries now i want to retrieve max (or highest value).

for this i have tried query as = SELECT MAX(RefNo) FROM sample; but this gives result as 'AB9' which is wrong and it is supposed to return 'AB10' as result.

To get this in Mysql i have modified the Query as = SELECT MAX(CONVERT(SUBSTRING_INDEX(RefNo,'B',-1),UNSIGNED INTEGER)) from sample where RefNo like 'AB%'

this work's fine in mysql but in hibernate (hql) query is not supported.

I hope you understand the scenerio and Please help me to solve the issue.

1 Answer 1

2

You should be able to use substring and cast to get the numeric part of the string and cast it to a number. Something like that (not tested) :

select max(cast(substring(sample.refNo, 3) as INTEGER)) from Sample sample ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.