0

guys thanks for your time and help i have this Mysql SQL

SELECT
IFNULL(SUM(IF((P_P LIKE 'P%'), 1, 0)), 0) AS numIn,
IFNULL(SUM(IF((P_A LIKE 'A%'), 1, 0)), 0) AS numOut
FROM PA_DATE

i try this on HQL

SELECT
COALESCE(SUM(IF((P_P LIKE 'P%'), 1, 0)), 0) AS numIn,
COALESCE(SUM(IF((P_A LIKE 'A%'), 1, 0)), 0) AS numOut
FROM PaDate

i get Error:

    java.lang.NullPointerException
at org.hibernate.dialect.Dialect$3.getReturnType(Dialect.java:102)

what i have to check?

1 Answer 1

1

I don't believe HQL supports if() as a function. The following should work in both databases:

SELECT SUM(case when P_P LIKE 'P%' then 1 else 0 end) AS numIn,
       SUM(case when P_A LIKE 'A%' then 1 else 0 end) AS numOut
FROM PaDate
3
  • ok, i see thanks for your time and help o have to use case when for this type of conditions thanks again for your time and help
    – Chacaman
    Feb 15, 2014 at 23:45
  • One question how i can add a second table in the sum?
    – Chacaman
    Feb 16, 2014 at 4:40
  • @Chacaman . . . You should ask another question. It always helps to have sample data and desired results. Feb 16, 2014 at 4:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.