Bonjour,
Je souhaiterais avoir une requete de ce type, mais ce n'est pas possible sous SQL-server 2005.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--------------------------------------------- Nb jours PRODUCTION
with Jour_Prod (JousProd,Affaire)as
(
	select 
		sum([Présence Réel Equipe]) as Nb_Jours,
		[Document No_]
	from dbo.[Production Chantier]
	where No_ = 'PR'
		and [Forecast Date] between '01/01/2000' and '31/07/2012'
		and [Présence Réel Equipe]>0
		and Région = 'CENTRE'
	group by [Document No_]
)
 
--------------------------------------------- Nb jours PRODUCTION 2012
with Jour_Prod_2012 (JousProd2012,Affaire)as
(
	select 
		sum([Présence Réel Equipe]) as Nb_Jours,
		[Document No_]
	from dbo.[Production Chantier]
	where No_ = 'PR'
		and [Forecast Date] between '01/01/2012' and '31/07/2012'
		and [Présence Réel Equipe]>0
		and Région = 'CENTRE'
	group by [Document No_]
)
 
--------------------------------------------------- Factures
with Facturation (Affaire,Ingenieur,FactPhaseB)as
(
select 
	Affaire as Affaire,	
	max([Code Ingénieur]) as Ingenieur,
	sum(cast([Phase B complet] as float)) as Fact_Phase_B
 
from dbo.[Statistiques]
where Région = 'CENTRE'
group by Affaire
order by Affaire
)
 
------------------------------------------------------ Devis
with Devis(Agence,Affaire,DevisPhaseB) as
(
select 
	max([Responsibility Center]) as Agence,
	[Job No_],
	sum(cast([Line Amount]as float)) as Devis_phaseB
from dbo.[Sales Line]
where [Phase Code] = 'B'
group by [Job No_]
)
 
	select 
		T4.Agence,
		T1.Affaire,
		T1.JousProd,
		T2.JousProd2012,		
		T3.Ingenieur,
		T3.FactPhaseB,
		T4.DevisPhaseB
 
	from dbo.[ Jour_Prod] T1
		left outer join [Jour_Prod_2012] T2
		on T1.Affaire = T2.Affaire
			left outer join [Facturation] T3
			on T1.Affaire = T3.Affaire 
				left outer join [Devis] T4
				on T1.Affaire = T4.Affaire
 
	order by  T4.Agence,T1.Affaire,
Comment puis je remplacer ou utiliser les differentes clauses WITH
MERCI