Question

I would like to use the if operator in the select statement, using an executeQuery command. Something like:

def tmpRec = BankStatement.executeQuery("select   SUM(IF(operation='CREDIT',cashAmount,-1*cashAmount)) from BankStatement group by portfolio,currency,code")

go but the IF operator doesn't work.

thank you

Était-ce utile?

La solution

Although I do not know Groovy SQL, in most DBMS the CASE statement is used as a conditional statement. Perhaps the following will work:

def tmpRec = BankStatement.executeQuery("select SUM(CASE WHEN operation='CREDIT' THEN cashAmount ELSE (-1*cashAmount) END) from BankStatement group by portfolio,currency,code")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top