TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tri Setia
1.3k
464
24.7k
How to update data barang on table barang using trigger in sql server
Apr 19 2021 4:14 AM
Hi guys,, I'm get trouble how to update value using trigger on table barang when data after update from table pembelian. For example first stock in table barang is 10, and then in table pembelian buy jumlahbeli 10, stock in table barang increased become 20. My question is how to update stock in table barang if in table pembelian existing data updated.
this is the xample in insert and update
select
*
from
barang
select
*
from
pembelian
insert
into
barang (namabarang,stockbarang)
Values
(
'Aqua'
,
'10'
)
insert
into
pembelian (idpembelian,namabarang,jumlahbeli)
Values
(
'1'
,
'Aqua'
,
'10'
)
Update
pembelian
Set
namabarang=
'Aqua'
,jumlahbeli=
'5'
Where
idpembelian=
'1'
--the correct result is 15 not 25 if this
--statement Update pembelian Set namabarang='Aqua',jumlahbeli='5' Where idpembelian='1' execute
this is trigger for added stockbarang in table barang
Create
trigger
[dbo].[tambahstockbarang]
on
[dbo].[pembelian]
for
insert
as
update
b
set
b.stockbarang=b.stockbarang+i.jumlahbeli
from
barang b
join
inserted i
on
b.namabarang=i.namabarang
this is trigger for update stockbarang in table barang
Create
trigger
[dbo].[ubahstockbarangpembelian]
on
[dbo].[pembelian]
after
insert
,
update
as
update
barang
set
barang.stockbarang=(barang.stockbarang+deleted.jumlahbeli)-inserted.jumlahbeli
from
inserted,deleted
where
deleted.namabarang=inserted.namabarang
please help correct my trigger for
update stockbarang.
Any help could be appriciate
Reply
Answers (
3
)
How I can return json object in api controller?
Send Value in .cs file.