Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 how to make a script sql with results like this (X
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nizw_r
Starting Member

Indonesia
2 Posts

Posted - 12/19/2014 :  09:37:39  Show Profile  Reply with Quote
how to make a script sql with results like this (XML)?

<ns1:inputRealisasiAPBDperPeriode'>
<realisasiApbd>
<kodeSatker>991947</kodeSatker>
<tahunAnggaran>2014</tahunAnggaran>
<kegiatan>
<kodeUrusanProgram>1.01</kodeUrusanProgram>
<namaUrusanProgram>Pendidikan</namaUrusanProgram>
<koderekening>
<kodeAkunRincian>01</kodeAkunRincian>
<namaAkunRincian>Retribusi</namaAkunRincian>
</koderekening>
<koderekening>
<kodeAkunRincian>02</kodeAkunRincian>
<namaAkunRincian>Gaji Pokok</namaAkunRincian>
</koderekening>
</kegiatan>
<kegiatan>
<kodeUrusanProgram>1.02</kodeUrusanProgram>
<namaUrusanProgram>Perpustakaan</namaUrusanProgram>
<koderekening>
<kodeAkunRincian>01</kodeAkunRincian>
<namaAkunRincian>Retribusi</namaAkunRincian>
</koderekening>
</kegiatan>
</realisasiapbd>
</ns1:inputRealisasiAPBDperPeriode'>

gbritton
Flowing Fount of Yak Knowledge

2780 Posts

Posted - 12/19/2014 :  11:16:25  Show Profile  Reply with Quote
look up the FOR XML clause of the SELECT statement:

http://msdn.microsoft.com/en-ca/library/ms178107.aspx
Go to Top of Page

nizw_r
Starting Member

Indonesia
2 Posts

Posted - 12/20/2014 :  06:41:06  Show Profile  Reply with Quote
I make a script like this :

SELECT KODE_GIAT ,
( select * from tm_rincian_obyek
where (tm_rincian_obyek.kode_rekening =tr_apbd.kode_rekening)
FOR XML AUTO, TYPE, ELEMENTS) AS kode_rekening
FROM
tr_apbd
group by kode_giat,kode_rekening
ORDER BY KODE_GIAT
FOR XML auto, ELEMENTS


Result :
<tr_apbd>
<KODE_GIAT>1.01.01.00.00</KODE_GIAT>
<kode_rekening>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>01</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.01</KODE_REKENING>
<RINCIAN_OBYEK>Gaji Pokok PNS/Uang Representasi</RINCIAN_OBYEK>
</tm_rincian_obyek>
</kode_rekening>
</tr_apbd>
<tr_apbd>
<KODE_GIAT>1.01.01.00.00</KODE_GIAT>
<kode_rekening>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>02</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.02</KODE_REKENING>
<RINCIAN_OBYEK>Tunjangan Keluarga</RINCIAN_OBYEK>
</tm_rincian_obyek>
</kode_rekening>
</tr_apbd>
<tr_apbd>
<KODE_GIAT>1.01.01.00.00</KODE_GIAT>
<kode_rekening>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>03</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.03</KODE_REKENING>
<RINCIAN_OBYEK>Tunjangan Jabatan</RINCIAN_OBYEK>
</tm_rincian_obyek>
</kode_rekening>
</tr_apbd>

but,
i want to get result like this :
<tr_apbd>
<KODE_GIAT>1.01.01.00.00</KODE_GIAT>
<kode_rekening>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>01</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.01</KODE_REKENING>
<RINCIAN_OBYEK>Gaji Pokok PNS/Uang Representasi</RINCIAN_OBYEK>
</tm_rincian_obyek>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>02</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.02</KODE_REKENING>
<RINCIAN_OBYEK>Tunjangan Keluarga</RINCIAN_OBYEK>
</tm_rincian_obyek>
<tm_rincian_obyek>
<KODE_AKUN>5</KODE_AKUN>
<KD_KEL_REK>1</KD_KEL_REK>
<KD_JENIS_REK>1</KD_JENIS_REK>
<KODE_OBYEK>01</KODE_OBYEK>
<KODE_RINCIAN>03</KODE_RINCIAN>
<KODE_REKENING>5.1.1.01.03</KODE_REKENING>
<RINCIAN_OBYEK>Tunjangan Jabatan</RINCIAN_OBYEK>
</tm_rincian_obyek>
</kode_rekening>
</tr_apbd>

please help..........
how to make produce the script as above, please help

Edited by - nizw_r on 12/20/2014 06:41:46
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000