Thursday, June 24, 2021

.::: Basic Store Procedure SQL Server :::.


1. Sample 1
-- SQL Query 1
select kode_barang, stok_barang from barang;

-- Store Procedure 1
create procedure kodestokbarang 
as 
select kode_barang, stok_barang from barang;

-- Output 1
exec kodestokbarang ;
select kode_barang, stok_barang from barang;


2. Sample 2
-- SQL Query 2
select KODE_BARANG as KD_BRG, min(JUMLAH_PASOK) as MINIMUM_PASOK from pasok group by KODE_BARANG;

-- Store Procedure 2
create procedure tttpasok
as 
select KODE_BARANG as KD_BRG, min(JUMLAH_PASOK) as MINIMUM_PASOK from pasok group by KODE_BARANG;

-- Output 2
exec tttpasok ;
select KODE_BARANG as KD_BRG, min(JUMLAH_PASOK) as MINIMUM_PASOK from pasok group by KODE_BARANG;


3. Sample 3
-- SQL Query 3
select KODE_PASOK as KD_PSK, count(JUMLAH_PASOK) as COUNT_PASOK from pasok group by KODE_PASOK;

-- Store Procedure 2
create procedure ttcountpasok
as 
select KODE_PASOK as KD_PSK, count(JUMLAH_PASOK) as COUNT_PASOK from pasok group by KODE_PASOK;

-- Output 3
exec ttcountpasok;
select KODE_PASOK as KD_PSK, count(JUMLAH_PASOK) as COUNT_PASOK from pasok group by KODE_PASOK;


4. Drop Store Procedure
DROP PROCEDURE kodestokbarang ;  
DROP PROCEDURE tttpasok;
DROP PROCEDURE tttcountpasok; 

No comments:

Post a Comment

Popular Posts