Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Nama : Boy candra Wijaya

Kelas: 17 IF 07

NIM : 17.11.1378
1. declare @cust varchar(20)
declare @nm varchar(30)

declare dataCust cursor for


select customer_id, name from Customers
where customer_id in (select customer_id from Purchases)
print 'kode cust Nama'
print '_________ _______________'
print''
open dataCust
fetch next from dataCust into @cust,@nm
while @@FETCH_STATUS = 0
begin
print @cust + ' ' + @nm
fetch next from dataCust into @cust,@nm
end
close dataCust
deallocate dataCust

2. declare @kodeItem varchar(10)


declare @namaBarang varchar(20)
declare dataItem cursor for
select top 3 item_id, name from items order by stok desc

open dataItem
fetch next from dataItem into @kodeItem, @namaBarang
print 'Kode Item '+' Nama Barang'
print '--------- '+' ------'
while @@fetch_status = 0
begin
print @kodeItem + ' - ' + @namaBarang
fetch next from dataItem into @kodeItem, @namaBarang
end
close dataItem
deallocate dataItem

3. declare @sellPrice date


declare @purchasePrice money
declare dataProfit cursor for

select date, sum(selling_price -


purchasing_price) from Purchases p join
Purchase_Items q on p.purchase_id = q.purchase_id
group by date
open dataProfit
fetch next from dataProfit into @sellPrice, @purchasePrice
print 'Kode item '+' Nama Barang '
print '___________ '+' __________'
while @@fetch_status = 0
begin
print convert (varchar(20), @sellPrice) + ' - ' + convert (varchar(20), @purchasePrice)
fetch next from dataProfit into @sellPrice, @purchasePrice
end
close dataProfit
deallocate dataProfit

4. DECLARE @profit VARCHAR(20)


DECLARE @tanggal DATETIME
DECLARE @banyak INT
DECLARE @total MONEY
DECLARE @min MONEY
DECLARE @max MONEY
DECLARE dataprofit CURSOR scroll FOR
SELECT date,
Sum(( selling_price - purchasing_price ) * amount) AS jumlah
FROM purchase_items
INNER JOIN purchases
ON purchases.purchase_id = purchase_items.purchase_id
GROUP BY date
OPEN dataprofit
FETCH first FROM dataprofit INTO @tanggal, @profit
SET @total = 0
SET @banyak = 0
SET @min = @profit
SET @max = @profit
PRINT 'Tanggal Profit'
PRINT '__________ ______________'
WHILE @@FETCH_STATUS = 0
BEGIN
SET @total = @total + @profit
SET @banyak = @banyak + 1
IF @min > @profit
BEGIN
SET @min = @profit
END
IF @max < @profit
BEGIN
SET @max = @profit
END
PRINT Format(@tanggal, 'yyyy-MM-dd') + ' - Rp '
+ @profit
FETCH next FROM dataprofit INTO @tanggal, @profit
END
PRINT 'Detail Profit Retail'
PRINT '------------------------------'
PRINT 'Total Profit = Rp '
+ CONVERT(VARCHAR(20), @total)
PRINT 'Rata-Rata = Rp '
+ CONVERT(VARCHAR(20), (@total / @banyak))
PRINT 'Profit Terendah = Rp '
+ CONVERT(VARCHAR(20), @min)
PRINT 'Profit Tertinggi = Rp '
+ CONVERT(VARCHAR(20), @max)
CLOSE dataprofit
DEALLOCATE dataprofit
--------------------------
5.

You might also like