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
| ;With Articles (code_article, nom_article, prix) as
(
select 1, 'article1', 2 union all
select 2, 'article2', 5 union all
select 3, 'article3', 4
)
, Commandes (num_commande, date_cmd, code_article, qte_cmd) as
(
select 1, '06/02/2011', 1, 10 union all
select 1, '06/02/2011', 3, 6 union all
select 1, '07/02/2011', 1, 5 union all
select 1, '07/02/2011', 2, 6
)
select art.code_article ,
art.nom_article ,
sel.dte as date_cmd,
coalesce(cmd.qte_cmd, 0) as qte_cmd
from Articles as art
cross join (select '07/02/2011' as dte) as sel
left outer join Commandes as cmd
on cmd.code_article = art.code_article
and cmd.date_cmd = sel.dte
code_article nom_article date_cmd qte_cmd
------------ ----------- ---------- -----------
1 article1 07/02/2011 5
2 article2 07/02/2011 6
3 article3 07/02/2011 0 |
Partager