Requête avec CTE : Erreur The multi-part identifier could not be bound
Bonjour à tous,
Je commence juste à travailler avec les CTE sous SQL Server, et je n'arrive pas à faire une requête sur 2 tables.
La requête suivante me retourne le message : The multi-part identifier "et.CodeEtape" could not be bound
Pouvez-vous me dire ce que je fais mal, je n'arrive pas à trouver... :oops:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
WITH Route_CTE AS (
SELECT [CodeEtapeDestination],[LibelleEtape]
FROM [dbo].[WU_Route] td, [dbo].[WU_Etape] et
WHERE td.[CodeEtape]=2 and td.[DefaultRoute]=1 and td.[CodeType]='TYPE1' and td.[CodeEtapeDestination]=et.[CodeEtape]
UNION ALL
SELECT td.[CodeEtapeDestination], et.[LibelleEtape] from [dbo].[WU_Etape] et,[dbo].[WU_Route] td
INNER JOIN Route_CTE rtce ON rtce.[CodeEtapeDestination]=td.[CodeEtape] and td.[DefaultRoute]=1 and td.[CodeType]='TYPE1' and td.[CodeEtapeDestination]=et.[CodeEtape]
)
SELECT * FROM Route_CTE
GO |
Merci d'avance !
Gaëlle.
Requete avec INNER JOIN ... ON
Bonjour
Vous pouvez essayer cette requête (ci-dessous)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
WITH Route_CTE AS (
SELECT
td.[CodeEtapeDestination],
et.[LibelleEtape]
FROM
[dbo].[WU_Route] td
INNER JOIN [dbo].[WU_Etape] et ON
td.[CodeEtape]=2 and td.[DefaultRoute]=1 and td.[CodeType]='TYPE1' and td.[CodeEtapeDestination]=et.[CodeEtape]
UNION ALL
SELECT
td.[CodeEtapeDestination],
et.[LibelleEtape]
FROM
[dbo].[WU_Etape] et
INNER JOIN [dbo].[WU_Route] td ON
td.[DefaultRoute]=1 and
td.[CodeType]='TYPE1' and
td.[CodeEtapeDestination]=et.[CodeEtape]
INNER JOIN Route_CTE rtce ON
rtce.[CodeEtapeDestination]=td.[CodeEtape]
)
SELECT * FROM Route_CTE |
La requête utilise les jointures INNER JOIN entre vos tables pour les deux "SELECT"
Cordialement
xyzwar