'WITH' 附近的语法错误
Syntax Error near to 'WITH'
我有一个问题,当我在 SQL Server 2014 中执行查询时,它正在工作,但是当我在 SQL Server 2005 中执行它时,我得到一个 "syntax error near 'WITH'";有人能帮我吗?
这是我的查询:
WITH TMP AS
(
SELECT
INWI.Date ,
Equipe_Cad.MatBCC,
INWI.Matricule_FS,
Equipe_Cad.Employe,
Equipe_Cad.Equipe,Equipe_Cad.Societe,
Projet.Projet,
INWI.Quantite,
RIGHT('0' + INWI.Tps_Net, 9) C
FROM
INWI
INNER JOIN
Equipe_Cad ON INWI.Matricule_FS = Equipe_Cad .MatFS
INNER JOIN
Projet ON Projet.EtapeTraitement = 'INWI_PREPAID'
WHERE
INWI.Date = '02/03/2018'
)
SELECT
Date,
MatBCC AS Matricule_BCC,
Matricule_FS,Employe AS Nom,Equipe,Societe,
Projet,
CAST(SUM(Quantite)AS int)AS Quantite ,
SUM(CAST(LEFT(C, 2) AS DECIMAL(10,8)) +
CAST(SUBSTRING(C, 4, 2) AS DECIMAL(10,8)) / 60 +
CAST(SUBSTRING(C, 7, 2) AS DECIMAL(10,8)) / 3600) AS Temps_Effectif
FROM
TMP
GROUP BY
Date, MatBCC, Matricule_FS, Employe, Equipe, Projet, Societe
谢谢
试试这个,它使用原始的 WITH 查询作为别名为 x 的子查询,然后您 select 来自子查询:
SELECT
x.Date,
x.MatBCC AS Matricule_BCC,
x.Matricule_FS,x.Employe AS Nom,x.Equipe,x.Societe,
x.Projet,
CAST(SUM(x.Quantite)AS int)AS Quantite ,
SUM(CAST(LEFT(x.C, 2) AS DECIMAL(10,8)) +
CAST(SUBSTRING(x.C, 4, 2) AS DECIMAL(10,8)) / 60 +
CAST(SUBSTRING(x.C, 7, 2) AS DECIMAL(10,8)) / 3600) AS Temps_Effectif
FROM
(
SELECT
INWI.Date ,
Equipe_Cad.MatBCC,
INWI.Matricule_FS,
Equipe_Cad.Employe,
Equipe_Cad.Equipe,Equipe_Cad.Societe,
Projet.Projet,
INWI.Quantite,
RIGHT('0' + INWI.Tps_Net, 9) C
FROM
INWI
INNER JOIN
Equipe_Cad ON INWI.Matricule_FS = Equipe_Cad .MatFS
INNER JOIN
Projet ON Projet.EtapeTraitement = 'INWI_PREPAID'
WHERE
INWI.Date = '02/03/2018') AS x
GROUP BY
x.Date, x.MatBCC, x.Matricule_FS, x.Employe, x.Equipe, x.Projet, x.Societe
我有一个问题,当我在 SQL Server 2014 中执行查询时,它正在工作,但是当我在 SQL Server 2005 中执行它时,我得到一个 "syntax error near 'WITH'";有人能帮我吗?
这是我的查询:
WITH TMP AS
(
SELECT
INWI.Date ,
Equipe_Cad.MatBCC,
INWI.Matricule_FS,
Equipe_Cad.Employe,
Equipe_Cad.Equipe,Equipe_Cad.Societe,
Projet.Projet,
INWI.Quantite,
RIGHT('0' + INWI.Tps_Net, 9) C
FROM
INWI
INNER JOIN
Equipe_Cad ON INWI.Matricule_FS = Equipe_Cad .MatFS
INNER JOIN
Projet ON Projet.EtapeTraitement = 'INWI_PREPAID'
WHERE
INWI.Date = '02/03/2018'
)
SELECT
Date,
MatBCC AS Matricule_BCC,
Matricule_FS,Employe AS Nom,Equipe,Societe,
Projet,
CAST(SUM(Quantite)AS int)AS Quantite ,
SUM(CAST(LEFT(C, 2) AS DECIMAL(10,8)) +
CAST(SUBSTRING(C, 4, 2) AS DECIMAL(10,8)) / 60 +
CAST(SUBSTRING(C, 7, 2) AS DECIMAL(10,8)) / 3600) AS Temps_Effectif
FROM
TMP
GROUP BY
Date, MatBCC, Matricule_FS, Employe, Equipe, Projet, Societe
谢谢
试试这个,它使用原始的 WITH 查询作为别名为 x 的子查询,然后您 select 来自子查询:
SELECT
x.Date,
x.MatBCC AS Matricule_BCC,
x.Matricule_FS,x.Employe AS Nom,x.Equipe,x.Societe,
x.Projet,
CAST(SUM(x.Quantite)AS int)AS Quantite ,
SUM(CAST(LEFT(x.C, 2) AS DECIMAL(10,8)) +
CAST(SUBSTRING(x.C, 4, 2) AS DECIMAL(10,8)) / 60 +
CAST(SUBSTRING(x.C, 7, 2) AS DECIMAL(10,8)) / 3600) AS Temps_Effectif
FROM
(
SELECT
INWI.Date ,
Equipe_Cad.MatBCC,
INWI.Matricule_FS,
Equipe_Cad.Employe,
Equipe_Cad.Equipe,Equipe_Cad.Societe,
Projet.Projet,
INWI.Quantite,
RIGHT('0' + INWI.Tps_Net, 9) C
FROM
INWI
INNER JOIN
Equipe_Cad ON INWI.Matricule_FS = Equipe_Cad .MatFS
INNER JOIN
Projet ON Projet.EtapeTraitement = 'INWI_PREPAID'
WHERE
INWI.Date = '02/03/2018') AS x
GROUP BY
x.Date, x.MatBCC, x.Matricule_FS, x.Employe, x.Equipe, x.Projet, x.Societe