2 番目のクエリのサブセットに特定のレコードを取得しようとしています。私が取得し続けるエラーは次のとおりです。それを解決することはできませんが、これが機能するかどうかを本当に知りたいです。
SELECT
e.entityid, e.entitynum, e.entityrole, eq.memotext, eq.fieldnum
FROM
( SELECT
DISTINCT entitynum
FROM Eqanswer, entities
LEFT JOIN Eqanswer
ON (Eqanswer.entitynum = entities.entitynum)
WHERE
entities.partyID LIKE
CASE
WHEN (entities.partyID LIKE '%Joe%'
OR entities.partyID LIKE '%Bob%'
OR entities.partyID LIKE '%Bill%')
THEN
(eqanswer.entityrole = 'F_TL'
AND (CONVERT(eqanswer.memotext, sql_date)=curDate() -5 ))
ELSE
(eqanswer.entityrole = 'F_TL' AND eqanswer.fieldnum = 160
AND (CONVERT(eqanswer.memotext,sql_date) = CurDate() -1 ))
END
) AS bs
LEFT JOIN Entities e ON (bs.entitynum = e.entitynum)
LEFT JOIN Eqanswer eq ON (bs.entitynum = eq.entitynum)
WHERE((eq.entityrole = 'R_CKLIST' AND eq.fieldnum in (8,9,10,11,34,35))
OR (eq.entityrole = 'F_TL' AND eq.fieldnum in (104,112,158,160))
OR (eq.entityrole = 'C_REVIEW' AND eq.fieldnum = 69))
ORDER BY e.entitynum
次の両方を試しました。
SELECT
e.entityid, e.entitynum, e.entityrole, eq.memotext, eq.fieldnum
FROM ( SELECT
DISTINCT entitynum
FROM Eqanswer, entities
LEFT JOIN Eqanswer
ON (Eqanswer.entitynum = entities.entitynum)
WHERE
entities.partyID
CASE
WHEN (entities.partyID LIKE '%Joe%'
OR entities.partyID LIKE '%Bob%'
OR entities.partyID LIKE '%Bill%')
THEN
(eqanswer.entityrole = 'F_TL'
AND eqanswer.fieldnum = 160
AND (CONVERT(eqanswer.memotext, sql_date)=curDate() -5 ))
ELSE
(eqanswer.entityrole = 'F_TL' AND eqanswer.fieldnum = 160
AND (CONVERT(eqanswer.memotext,sql_date) = CurDate() -1 ))
END
) AS bs
LEFT JOIN Entities e ON (bs.entitynum = e.entitynum)
LEFT JOIN Eqanswer eq ON (bs.entitynum = eq.entitynum)
WHERE((eq.entityrole = 'R_CKLIST' AND eq.fieldnum in (8,9,10,11,34,35))
OR (eq.entityrole = 'F_TL' AND eq.fieldnum in (104,112,158,160))
OR (eq.entityrole = 'C_REVIEW' AND eq.fieldnum = 69))
ORDER BY e.entitynum
と
SELECT e.entityid, e.entitynum, e.entityrole, e.thestatus, eq.memotext, eq.dateentered, eq.datechgd, eq.fieldnum, e.docloc
FROM (SELECT DISTINCT eqanswer.entitynum FROM eqanswer
LEFT JOIN entities ON (Eqanswer.entitynum = entities.entitynum)
WHERE entities.partyID
CASE WHEN (entities.party3ID LIKE '%Joe%'
OR entities.party3ID LIKE '%Bob%'
OR entities.party3ID LIKE '%Bill%')
THEN
CASE WHEN (eqanswer.entityrole = 'F_TL'
AND eqanswer.fieldnum = 160
AND (CONVERT(eqanswer.memotext, sql_date)=curDate() -5 ))
THEN 1 ELSE 0 END
ELSE
CASE WHEN (eqanswer.entityrole = 'F_TL'
AND eqanswer.fieldnum = 160
AND (CONVERT(eqanswer.memotext,sql_date) = CurDate() -1 ))
THEN 1 ELSE 0 END
END = 1
) AS bs
LEFT JOIN Entities e ON (bs.entitynum = e.entitynum)
LEFT JOIN Eqanswer eq ON (bs.entitynum = eq.entitynum)
WHERE((eq.entityrole = 'R_CKLIST' AND eq.fieldnum in (8,9,10,11,34,35))
OR (eq.entityrole = 'F_TL' AND eq.fieldnum in (104,112,158,160))
OR (eq.entityrole = 'C_REVIEW' AND eq.fieldnum = 69))
ORDER BY e.entitynum
どちらもエラーをスローしていますが、それは構文エラーのようなものです (私のせいです)。