1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| create database test;
use test
go
drop table dbo.TS_articles;
go
create table dbo.TS_articles
(No_Cpte int
,No_Article int not null unique
,Nom_Article varchar(50)
,Stock_Actuel int
,CONSTRAINT PK_No_Cpte primary key (No_Cpte)
)
Insert into dbo.TS_articles values
(11 ,1 ,'Art1' ,0 )
,(12 ,2 ,'Art2' ,0 )
,(13 ,3 ,'Art3' ,0 )
,(14 ,4 ,'Art4' ,0 )
,(15 ,5 ,'Art5' ,0 )
;
go
drop table dbo.Ts_Transaction
go
create table dbo.Ts_Transaction
(No_transaction int CONSTRAINT PK_No_Transaction primary key
,No_Article int REFERENCES TS_articles(No_Article )
,Quantite int
)
insert into dbo.Ts_Transaction values
,(1, 1, -1 )
,(2, 2, 2000 )
,(3, 2, 1000 )
,(4, 2, 400 )
,(5, 2, 600 )
,(6, 3, 150 )
,(7, 1, -1 )
,(8, 3, 200 )
,(9, 5, 333 )
;
With pseudo_vue as
(select TS_Articles.No_Article, Stock_Actuel,[Quantite]
from TS_Articles INNER JOIN TS_Transactions
ON TS_Articles.No_Article = TS_Transactions.No_Article
)
update pseudo_vue
set Stock_Actuel = Stock_Actuel+[Quantite]
; |
Partager