Am using a UNION query to collate two disparate queries, and then want to use that query nested within another. This is what I have:
but SQL Server spits out an error about an error near the closing bracket on the last line. The UNION query works fine on its own, by the way.
What's wrong?
Thanks.
Code:
SELECT DISTINCT cid, logdt, MIN(closedt) FROM
(
SELECT cid, logdt, closedt
FROM Call C
WHERE datediff(ss, C.logdt, C.closedt) < 21600
UNION
SELECT c.cid, c.logdt, MAX(h.adddt) AS resolvedt
FROM Call C INNER JOIN CallHist h ON c.cid=h.cid
WHERE datediff(ss, C.logdt, h.adddt) < 21600
AND h.txt='Preclose'
GROUP BY c.cid, c.logdt
)
but SQL Server spits out an error about an error near the closing bracket on the last line. The UNION query works fine on its own, by the way.
What's wrong?
Thanks.