how to make the following query as efficient as po
There is a parameter in WHERE clause. I want to use the following result (say A) inner join another query (say B) which also has the same parameter in WHERE clause to get the query C. The query speed is slow.(we can take the parameter criteria away from where clause in A and B, and put it in C's where clause). I do not know if there is a good way to make the query as efficient as possible.
Thanks for your concern, and thank you for your any answer in advance!
SELECT DTree.DataID, DTree.Name, LLAttrData.VerNum,
LLAttrData.DefID, MAX(CASE WHEN ((DefID = 1682417 AND
AttrID = 3) OR
(DefID = 1682385 AND AttrID = 2) OR
(DefID = 1682445 AND AttrID = 3) OR
(DefID = 1682425 AND AttrID = 3) OR
(DefID = 1682453 AND AttrID = 2)) THEN ValStr ELSE NULL
END) AS DwgNo, MAX(CASE WHEN ((DefID = 1682417 AND
AttrID = 8) OR
(DefID = 1682385 AND AttrID = 5) OR
(DefID = 1682445 AND AttrID = 7) OR
(DefID = 1682425 AND AttrID = 7) OR
(DefID = 1682453 AND AttrID = 6)) THEN ValStr ELSE NULL
END) AS Sheet, MAX(CASE WHEN ((DefID = 1682417 AND
AttrID = 6) OR
(DefID = 1682385 AND AttrID = 4) OR
(DefID = 1682445 AND AttrID = 5) OR
(DefID = 1682425 AND AttrID = 5) OR
(DefID = 1682453 AND AttrID = 4)) THEN ValStr ELSE NULL
END) AS Version, MAX(CASE WHEN ((DefID = 1682417 AND
AttrID = 11) OR
(DefID = 1682385 AND AttrID = 8) OR
(DefID = 1682445 AND AttrID = 8) OR
(DefID = 1682425 AND AttrID = 8) OR
(DefID = 1682453 AND AttrID = 7)) THEN ValStr ELSE NULL
END) AS Title
FROM DTree INNER JOIN
LLAttrData ON (DTree.VersionNum = LLAttrData.VerNum) AND
(DTree.DataID = LLAttrData.ID)
WHERE (((DTree.Name) LIKE '%parametr%') AND ((LLAttrData.DefID)
= 1682417 OR
(LLAttrData.DefID) = 1682385 OR
(LLAttrData.DefID) = 1682445 OR
(LLAttrData.DefID) = 1682425 OR
(LLAttrData.DefID) = 1682453))
GROUP BY DTree.DataID, DTree.Name, LLAttrData.VerNum,
LLAttrData.DefID
|