0

Please help me to write HQL query for the following SQL query:

SELECT MAX(CAST(SUBSTRING([columnname], 6) AS UNSIGNED))+1 
FROM [Tablename] 
WHERE DistrCode = [(value)];
Jan Papenbrock
  • 1,037
  • 1
  • 11
  • 24
G V
  • 65
  • 1
  • 10
  • It is working in mysql fine but in the form of hql query it is not working. I hope u understand – G V May 25 '16 at 09:11
  • 1
    Please divide your questions into sub parts. Like do you know which part is not working-> here is an idea try max, cast, substring separately and see what is the problem. And check these links: http://stackoverflow.com/questions/4791325/how-do-i-write-hql-query-with-cast http://stackoverflow.com/questions/25121520/hql-substring-last-x-characters – Mihriban Minaz May 25 '16 at 09:34
  • i checked those links before posting this. Mr.jan's answer works perfectly – G V May 25 '16 at 11:20
  • @GV : I guess , Minaz is simply asking you to ask a more clear question as what you tried and what challenges you facing. +1 since you are new & don't wish to discourage you due to negative votes. – Sabir Khan Nov 26 '19 at 13:38

1 Answers1

1

I cannot try it myself, but just from searching around I found these probable solutions:

Solution 1

SELECT MAX(CAST(SUBSTRING([columnname], 6) AS UNSIGNED INTEGER))+1

Solution 2

SELECT MAX(CAST(SUBSTRING([columnname], 6) AS INTEGER))+1

Maybe you can try both and report back, which one worked.

Jan Papenbrock
  • 1,037
  • 1
  • 11
  • 24