use @var in mysql select query for dataset

0

Hi

if I want to use this query below 

SELECT b.naam, b.voornaam,IF(bu.typeid='2',bu.bedrag,0) AS 'inkomst', IF(bu.typeid='1',bu.bedrag,0) AS 'uitgave',bu.datum,
@total:= @total + IF(bu.typeid=2,bu.bedrag,0) -IF(bu.typeid=1,bu.bedrag,0) AS 'totaal'
FROM bewoners_uitgaven bu
JOIN bewoners b ON b.id = bu.bewonerID
JOIN kl_bewoners_uitgave_type kl ON kl.id = bu.typeid
WHERE b.Id =150;

I got null as a result for totaal, can I use @var in my mysqlstatement?

kevin.de.wulf's picture
Joined: Oct 12 2015 - 12:11am
Last seen: 1 year 5 months ago

2 Answers:

0

I solved it,

if I add an extra join 

JOIN (SELECT @total :=0 ) r

it works

kevin.de.wulf's picture
Joined: Oct 12 2015 - 12:11am
Last seen: 1 year 5 months ago
0

Glad you were able to resolve it Kevin. On a side note though, yes you can use variables in your SQL query for jasper reports.

Thanks.

m.kamran's picture
141
Joined: Nov 3 2017 - 3:11am
Last seen: 1 year 4 months ago
Feedback
randomness