contoh variabel mysql:
SELECT @a:=(IFNULL(
SELECT SaldoAwal
FROM tblSaldoAwal as a
WHERE a.KdBarang=b.KdBarang
AND MONTH(TglTrans)=3
AND YEAR(TglTrans)=2006), 0) AS SA,
@b:=SUM(Debet) AS TDebet,
@c:=SUM(Kredit) AS TKredit,
(@a+@b)-@c AS SaldoAkhir
FROM tblKartuStok_barang AS b
WHERE kdbarang='xxxxx' AND MONTH(TglTrans) AND YEAR(TglTrans)
GROUP BY KdBarang