SQL
SQL
open view_customer
--FETCH NEXT FROM view_customer
--FETCH PRIOR FROM view_customer
FETCH RELATIVE 2 FROM view_customer
--tembak datanya
FETCH ABSOLUTE 15 from view_customer
--variabel global yg kasi tau fetch status sblmny, karna ga pilih data
FETCH NEXT FROM view_customer
while @@FETCH_STATUS = 0
FETCH NEXT FROM view_customer
SELECT @@FETCH_STATUS
------
declare @name varchar(100)
declare @email varchar(100)
begin
print(@name + ' ' + @email)
FETCH NEXT FROM view_customer into @name, @email
end
----
FETCH NEXT FROM view_customer
WHILE @@FETCH_STATUS = 0
FETCH NEXT FROM view_customer
------
CLOSE view_customer
DEALLOCATE view_customer
-----
declare view_transaction cursor scroll
for select th.TransactionDate, mc.CustomerName from MsCustomer mc
join TransactionHeader th on mc.CustomerID = th.CustomerID
open view_transaction
declare @customerName varchar(255)
declare @transactionId char (5)
declare @transactionDate Date
fetch first from view_transaction into @customername, @transactionID,
@transactionDate
while @@FETCH_STATUS =0
begin
print('invoice number: '+ @transactionID)
print('Date : '+convert(varchar, @transactionDate))
print('Customer Name : '+@customerName)
open view_detail
fetch next from view_detail into @fishId, @fishName, @fishPrice, @quantity
while @@FETCH_STATUS=0
begin
print(Cast(@no as varchar) + '. '+@fishName + ' - ' + cast(@fishPrice as
varchar) + ' - ' + cast(@quantity as varchar) + ' pcs')
set @totalPrice = @totalPrice + @fishPrice * @quantity
set @no = @no +1
CLOSE view_transaction
DEALLOCATE view_transaction
tanpa scroll cuma next
next pun bisa pake scroll juga
===============
go
declare view_transaction cursor scroll
for select mc.CustomerName, th.TransactionID, th.TransactionDate
from MsCustomer mc
join TransactionHeader th
on mc.CustomerID=th.CustomerID
open view_transaction
declare @customerName varchar(255)
declare @transactionID char(5)
declare @transactionDate date
fetch first from view_transaction into
@customerName,@transactionID,@transactionDate
while @@FETCH_STATUS=0
begin
print(@customerName+' '+@transactionID+' '+cast(@transactionDate as varchar))
declare @fishID char(5)
declare @fishName varchar(100)
declare @fishPrice float
declare @quantity int
declare @no int
declare @totalPrice float
set @no=1
set @totalPrice=0
open view_detail
fetch next from view_detail into @fishID,@fishName,@fishPrice,@quantity
while @@FETCH_STATUS=0
begin
print(cast(@no as varchar)+'. '+@fishname +' '+cast(@fishPrice as varchar)+'
'+cast(@quantity as varchar))
set @totalPrice=@totalPrice+@fishPrice*@quantity
set @no= @no +1
fetch next from view_detail into @fishID,@fishName,@fishPrice,@quantity
end
print('Total Price '+cast(@totalPrice as varchar))
close view_detail
deallocate view_detail
fetch next from view_transaction into
@customerName,@transactionID,@transactionDate
End
close view_transaction
deallocate view_transaction
go
--TRIGER----------------------
--INSERT UPDATE DELETE
begin tran
rollback
go
--instead of,ga lakuin yg dikanannya (insert) tapi yg didalam trigger dilakuin
alter trigger new_customer on MsCustomer
instead of insert
as
begin
declare @dob date
--end
--else
-- print('Success')
end
select DATEDIFF(day, Getdate(), '2022-07-26')
--for kalo
--DELETE-----------
--trigger ga hanya 1 event
select * from Mscustomer
go
go
--SELECT
--@customerID = CustomerID,
--@customerName = CustomerName,
--@customerGender = CustomerGender,
--@customerAddress = CustomerAddress,
--@customerEmail = CustomerEmail,
--@customerDOB = CustomerDOB
--FROM deleted
_
end