php cannot execute procedure sql server -


i have query this,

declare @tmpspj table(kd_rek_1 tinyint, kd_rek_2 tinyint, kd_rek_3 tinyint, kd_rek_4 tinyint, kd_rek_5 tinyint, anggaran money, gaji_l money, gaji_i money, ls_l money, ls_i money, up_l money, up_i money)     declare @peny_spj bit     declare @tahun varchar(4), @kd_urusan varchar(3), @kd_bidang varchar(3), @kd_unit varchar(3), @kd_sub varchar(3), @bulan tinyint      set @kd_urusan = '1'     set @kd_bidang = '2'     set @kd_unit = '1'     set @kd_sub = '0'     set @tahun = '2013'     set @bulan = '2'      if isnull(@kd_urusan, '') = '' set @kd_urusan = '%'     if isnull(@kd_bidang, '') = '' set @kd_bidang = '%'     if isnull(@kd_unit, '') = '' set @kd_unit = '%'     if isnull(@kd_sub, '') = '' set @kd_sub = '%'      select @peny_spj = isnull(peny_spj, 0)     ref_setting     tahun = @tahun      insert @tmpspj     select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5,         sum(a.anggaran), sum(a.gaji_l), sum(a.gaji_i), sum(a.ls_l), sum(a.ls_i),         sum(a.up_l), sum(a.up_i)             (         select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, a.total anggaran, 0 gaji_l, 0 gaji_i, 0 ls_l, 0 ls_i, 0 up_l, 0 up_i         ta_rask_arsip         (a.kd_rek_1 = 5) , (a.tahun = @tahun) , (a.kd_perubahan = (select max(kd_perubahan) ta_rask_arsip_perubahan (kd_perubahan in (4, 6, 8)) , (left(convert(varchar, tgl_perda, 112), 6) <= (@tahun + right('0' + convert(varchar, @bulan), 2))) , (tahun = @tahun))) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0,              case             when b.jn_spm in (1, 2, 4) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) a.nilai             else 0             end gaji_l, 0 gaji_i,              case             when b.jn_spm in (1, 2, 4) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) 0             else a.nilai             end ls_l, 0 ls_i,              0 up_l, 0 up_i         ta_spm_rinc inner join             ta_spm b on a.tahun = b.tahun , a.no_spm = b.no_spm inner join             ta_sp2d c on b.tahun = c.tahun , b.no_spm = c.no_spm         (b.jn_spm = 3) , (b.kd_edit <> 2) , (left(convert(varchar, c.tgl_sp2d, 112), 6) < (@tahun + right('0' + convert(varchar, @bulan), 2))) , (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             , (a.kd_rek_1 = 5)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0, 0 gaji_l,               case             when b.jn_spm in (1, 2, 4) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) a.nilai             else 0             end gaji_i, 0 ls_l,              case             when b.jn_spm in (1, 2, 4) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) 0             else a.nilai             end ls_i, 0 up_l,             0 up_i         ta_spm_rinc inner join             ta_spm b on a.tahun = b.tahun , a.no_spm = b.no_spm inner join             ta_sp2d c on b.tahun = c.tahun , b.no_spm = c.no_spm         (b.jn_spm = 3) , (b.kd_edit <> 2) , (left(convert(varchar, c.tgl_sp2d, 112), 6) = (@tahun + right('0' + convert(varchar, @bulan), 2))) , (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             , (a.kd_rek_1 = 5)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0 anggaran, 0 gaji_l, 0 gaji_i, 0 ls_l, 0 ls_i, a.nilai_setuju up_l, 0 up_i         ta_pengesahan_spj_rinc inner join             ta_pengesahan_spj b on a.tahun = b.tahun , a.no_pengesahan = b.no_pengesahan         (left(convert(varchar, b.tgl_pengesahan, 112), 6) < (@tahun + right('0' + convert(varchar, @bulan), 2))) , (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0 anggaran, 0 gaji_l, 0 gaji_i, 0 ls_l, 0 ls_i, 0 up_l, a.nilai_setuju up_i         ta_pengesahan_spj_rinc inner join             ta_pengesahan_spj b on a.tahun = b.tahun , a.no_pengesahan = b.no_pengesahan         (left(convert(varchar, b.tgl_pengesahan, 112), 6) = (@tahun + right('0' + convert(varchar, @bulan), 2))) , (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0,              case             when b.jn_spm in (2, 5) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1)                  case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             else 0             end gaji_l, 0 gaji_i,              case             when b.jn_spm in (2, 5) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) 0             else                 case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             end ls_l, 0 ls_i,              case             when b.jn_spm in (2, 5)                 case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             else 0             end up_l, 0 up_i         ta_penyesuaian_rinc inner join             ta_penyesuaian b on a.tahun = b.tahun , a.no_bukti = b.no_bukti         (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             , (b.jns_p1 = 1) , (left(convert(varchar, b.tgl_bukti, 112), 6) < (@tahun + right('0' + convert(varchar, @bulan), 2)))             , (@peny_spj = 1)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0,              0 gaji_l,              case             when b.jn_spm in (2, 5) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1)                  case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             else 0             end gaji_i,              0 ls_l,             case             when b.jn_spm in (2, 5) 0             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) 0             else                 case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             end ls_i,              0 up_l,              case             when b.jn_spm in (2, 5)                 case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             else 0             end up_i         ta_penyesuaian_rinc inner join             ta_penyesuaian b on a.tahun = b.tahun , a.no_bukti = b.no_bukti         (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             , (b.jns_p1 = 1) , (left(convert(varchar, b.tgl_bukti, 112), 6) = (@tahun + right('0' + convert(varchar, @bulan), 2)))             , (@peny_spj = 1)          union          select a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5, 0,              case             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1)                  case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             else 0             end gaji_l, 0 gaji_i,              case             when (a.kd_rek_1 = 5) , (a.kd_rek_2 = 1) , (a.kd_rek_3 = 1) , (a.kd_rek_4 = 1) 0             else                 case a.d_k                 when 'd' a.nilai                 else -a.nilai                 end             end ls_l, 0 ls_i,              0 up_l, 0 up_i         ta_jurnal_rinc inner join             ta_jurnal b on a.tahun = b.tahun , a.no_bukti = b.no_bukti         (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             , (left(convert(varchar, b.tgl_bukti, 112), 6) < (@tahun + right('0' + convert(varchar, @bulan), 2)))             , (a.kd_rek_1 = 5) , (@peny_spj = 1) , (b.no_bku <> 9999)         )     group a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5      select top 1 c.kd_urusana, c.kd_bidanga, c.kd_unita, c.kd_suba,         c.kd_urusan_gab, c.kd_bidang_gab, c.kd_unit_gab, c.kd_sub_gab,         c.nm_urusan_gab test, c.nm_bidang_gab, c.nm_unit_gab, c.nm_sub_unit_gab,         b.nm_rek_5,         convert(varchar, a.kd_rek_1) + ' . ' + convert(varchar, a.kd_rek_2) + ' . ' + convert(varchar, a.kd_rek_3) + ' . ' + right('0' + convert(varchar, a.kd_rek_4), 2) + ' . ' + right('0' + convert(varchar, a.kd_rek_5), 2) kd_rek_5_gab,         a.anggaran, a.gaji_l, a.gaji_i, a.gaji_l + a.gaji_i gaji_t,         a.ls_l, a.ls_i, a.ls_l + a.ls_i ls_t,         a.up_l, a.up_i, a.up_l + a.up_i up_t,         a.gaji_l + a.gaji_i + a.ls_l + a.ls_i + a.up_l + a.up_i total_spj,         a.anggaran - (a.gaji_l + a.gaji_i + a.ls_l + a.ls_i + a.up_l + a.up_i) sisa,         c.nm_pimpinan, c.nip_pimpinan, c.jbt_pimpinan, c.nm_bendahara, c.nip_bendahara, c.jbt_bendahara     @tmpspj inner join         ref_rek_5 b on a.kd_rek_1 = b.kd_rek_1 , a.kd_rek_2 = b.kd_rek_2 , a.kd_rek_3 = b.kd_rek_3 , a.kd_rek_4 = b.kd_rek_4 , a.kd_rek_5 = b.kd_rek_5,         (         select @kd_urusan kd_urusana, @kd_bidang kd_bidanga, @kd_unit kd_unita, @kd_sub kd_suba,             @kd_urusan kd_urusan_gab,             @kd_urusan + ' . ' + right('0' + @kd_bidang, 2) kd_bidang_gab,             @kd_urusan + ' . ' + right('0' + @kd_bidang, 2) + ' . ' + right('0' +  @kd_unit, 2) kd_unit_gab,             @kd_urusan + ' . ' + right('0' + @kd_bidang, 2) + ' . ' + right('0' +  @kd_unit, 2) + ' . ' + right('0' +  @kd_sub, 2) kd_sub_gab,             e.nm_urusan nm_urusan_gab, d.nm_bidang nm_bidang_gab, c.nm_unit nm_unit_gab, b.nm_sub_unit nm_sub_unit_gab,             a.nm_pimpinan nm_pimpinan, a.nip_pimpinan nip_pimpinan, a.jbt_pimpinan jbt_pimpinan,             g.nm_bendahara, g.nip_bendahara, g.jbt_bendahara         ta_sub_unit inner join             ref_sub_unit b on a.kd_urusan = b.kd_urusan , a.kd_bidang = b.kd_bidang , a.kd_unit = b.kd_unit , a.kd_sub = b.kd_sub inner join             ref_unit c on b.kd_urusan = c.kd_urusan , b.kd_bidang = c.kd_bidang , b.kd_unit = c.kd_unit inner join             ref_bidang d on c.kd_urusan = d.kd_urusan , c.kd_bidang = d.kd_bidang inner join             ref_urusan e on d.kd_urusan = e.kd_urusan inner join             (             select top 1 tahun, kd_urusan, kd_bidang, kd_unit, kd_sub             ta_sub_unit             (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             order tahun, kd_urusan, kd_bidang, kd_unit, kd_sub             ) f on a.tahun = f.tahun , a.kd_urusan = f.kd_urusan , a.kd_bidang = f.kd_bidang , a.kd_unit = f.kd_unit , a.kd_sub = f.kd_sub left outer join             (             select tahun, kd_urusan, kd_bidang, kd_unit, kd_sub, min(nama) nm_bendahara, min(nip) nip_bendahara, min(jabatan) jbt_bendahara             ta_sub_unit_jab             (a.kd_jab = 4) , (a.tahun = @tahun) , (a.kd_urusan @kd_urusan) , (a.kd_bidang @kd_bidang) , (a.kd_unit @kd_unit) , (a.kd_sub @kd_sub)             group tahun, kd_urusan, kd_bidang, kd_unit, kd_sub             ) g on f.tahun = g.tahun , f.kd_urusan = g.kd_urusan , f.kd_bidang = g.kd_bidang , f.kd_unit = g.kd_unit , f.kd_sub = g.kd_sub         ) c     order a.kd_rek_1, a.kd_rek_2, a.kd_rek_3, a.kd_rek_4, a.kd_rek_5 

and php trying execute it,

include ($_server['document_root'] . '/simda/classes/koneksi.php'); global $conn; $kon = new koneksi(); $conn = $kon->bukakoneksi(); $params = array(); $options = array("scrollable" => sqlsrv_cursor_keyset); $rs = sqlsrv_query($conn, $query, $params, $options); //$row = sqlsrv_fetch_array($rs, sqlsrv_fetch_assoc); if ($rs != null) {     while ($row = sqlsrv_fetch_array($rs, sqlsrv_fetch_assoc)) {         echo 'testt';     }     $num_rows = sqlsrv_num_rows($rs);     echo $num_rows; } 

the result number of row, 132 rows (although in query wrote "top 1") "testt" not showed. , if execute query directly in sql server showed me 1 data supposed show. , if try using query "select * my_table", "testt" showed correctly. don't know what's wrong in there. confusing. there wrong in code? please me, sry english, thank you

make stored procedure query (say, my_sp), , run php: "exec my_sp"


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -