Wednesday, March 24, 2010

Crosstab and having SQL that display star rating

//lets say we have this SQL in crosstab datawindow in Powerbuilder (i'm using 10.2.x)

select a.KOD, d.PIHAK , c.JUMBINTANG, c.MULA, c.AKHIR, a.KOD_JENIS, e.SINGKATN, to_char(b.TKH_SEMASA, 'yyyy') as compute_0008_year
from main a, semasa b, star c, pihak d, kdfaklt e
where a.KOD = b.KOD (+)
and b.SEMASA is not null
and a.PIHAK = d.PIHAK (+)
and a.PTJ = e.KDFKLT
having  (count(to_char(b.TKH_SEMASA, 'yyyy')) between c.mula and c.AKHIR)
group by a.KOD, d.PIHAK , c.JUMBINTANG, c.MULA, c.AKHIR, a.KOD_JENIS, e.SINGKATN, to_char(b.TKH_SEMASA, 'yyyy')
order by to_char(b.TKH_SEMASA, 'yyyy'), a.KOD_PEKA

//your crosstab definition is like this

//you have datawindow output like this



//but you want an output like below?

//in a dialogbox format property of the displayed number in datawindow code this:-

Thursday, March 11, 2010

Powerbuilder Openwithparm

 string ls_stafno
//Open a response window w_find passing a string
ls_stafno = '007'
openwithparm(w_find, ls_stafno, parent)

//other example passing a structure
struc_staff  lstrc_staff
lstrc_staff.stafno = '007'
lstrc_staff.name = 'James Bond'
openwithparm(w_find, lstrc_staff)

Wednesday, March 10, 2010

Connecting Powerbuilder to Oracle 10g


sqlca.DBMS = "O10 Oracle10g (10.1.0)"
sqlca.LogPass = "tiger"
sqlca.ServerName = "server"
sqlca.LogId = "scott"
sqlca.AutoCommit = False
sqlca.DBParm = "CommitOnDisconnect='No',Async=1,PBCatalogOwner='scott'"

connect using sqlca;
dw_1.settransobject(sqlca)

Tuesday, March 9, 2010

More CASE and DECODE in oracle SQL

SELECT b.TARIKH,
b.KOD_PROJEK,
a.NAMA_PROJEK,
b.KOD_VOT, 
b.DASAR,
b.KET,
(select d.NAMA_TRANS from sbp_trans d where d.JENIS = b.JENIS_TRANS) as trans,
b.LO as rujukan,
(case when b.jenis_trans in (3,4) then b.amaun
else null
end) as debit,
DECODE(b.JENIS_TRANS, 5, b.AMAUN, null) as kredit,
(case when b.jenis_trans not in (1,2,6) then null
else b.AMAUN
end) as amt_col8, 
b.JENIS_TRANS,
(select c.AMAUN from sbp_budget c where c.KOD_VOT = b.kod_vot and c.DASAR = b.dasar and c.PTJ = a.PTJ and c.SPTJ = a.SPTJ
and c.thn_blj = :as_thnblj and c.JENIS = 1) as peruntukan,
b.KOD_SODO
FROM PROJEK a, BELANJA b
WHERE b.KOD_VOT like :as_vot
AND b.DASAR like :as_dasar
AND a.KOD_PROJEK = b.KOD_PROJEK
AND substr(a.KOD_PROJEK, 1,4) = :as_thnblj
AND a.PTJ = :as_ptj
AND a.SPTJ like :as_sptj