这是我之前的问题Concatenate 2 rows in a complex SQL query的后续。
这是我从这个问题中得到的:
PARAMETERS [CurrAxe] TEXT ( 255 ), [CurrOTP] TEXT ( 255 ), [CurrClient] TEXT (
255 ), [StartDate] DATETIME, [EndDate] DATETIME;
SELECT q.Projet, *
FROM (faitssaillants f
LEFT JOIN employes e
ON f.utilisateur = e.cip)
INNER JOIN (
SELECT s1.otp,
[s1].[valeur] & "," & [s2].[valeur] AS Projet
FROM (
SELECT otp, valeur
FROM tb_sommaire
WHERE [variable] = 'TitreMandat') AS s1
INNER JOIN (
SELECT otp, valeur
FROM tb_sommaire
WHERE [variable] = 'NomInstallation') AS s2
ON s1.otp = s2.otp) q
ON f.otp = q.otp
WHERE f.otp = [currotp]
AND f.client LIKE [currclient]
AND f.axe LIKE [curraxe]
AND Datevalue([dateinsertion])
Between [startdate] And [enddate]
ORDER BY f.dateinsertion DESC;
如果我想用 [variable] = 'something else' 而不是 'TitreMandat' 或 'NomInstallation' 添加另一行(我们将其命名为 s3)怎么办?是否可以将所有 tb_sommaire.variable 作为字段并将 tb_sommaire.valeur 作为 tb_sommaire.otp = faitssaillants.otp 的值?它可能也会解决我未来的问题。