Reputation: 326
I have one field named 'uniqueCode' which formed using city and salesPersonId and some count. format: uniqueCode = City + SalesPersonId + 101 example: AHM1101=AHM+1+101 Now, I want a method which would take city and salespersonId and return me max of uniqueId. I have written query like this:
@Query("SELECT max(s.uniqueCode) FROM ServiceProvider s WHERE s.uniqueCode LIKE :cityCode:salesPersonId%")
public String maxUniqueCode(@Param("cityCode") String cityCode, @Param("salesPersonId") Long salesPersonId);
But it is giving error that Unexpected token: salesPersonId . What is the correct way to write this query. Thanks.
Upvotes: 1
Views: 879
Reputation: 34846
Try to join your params into single string using CONCAT(:cityCode, :salesPersonId, '%')
and it should work:
@Query("SELECT max(s.uniqueCode) FROM ServiceProvider s WHERE s.uniqueCode LIKE CONCAT(:cityCode, :salesPersonId, '%')")
public String maxUniqueCode(@Param("cityCode") String cityCode, @Param("salesPersonId") Long salesPersonId);
Upvotes: 1
Reputation: 6765
The like operand is expecting a string value with apostrophes around it. For example, if you are looking for the AHM1%, the correct way to write this query would be - SELECT max(s.uniqueCode) FROM ServiceProvider s WHERE s.uniqueCode LIKE 'AHM1%'
Try adding those around your search string and see if it helps.
Upvotes: 0