Q&A for professional and enthusiast programmers
-- This query displays the questions where the two users meet.
-- It accepts two paramaters:
-- @AskerID => the one who raised the question
-- @AnswererID => the one who answered
-- It also display whether the answer has been accepted or not.
-- All users are ALLOWED to fork this query for improvements.
DECLARE @AskerID int = ##AskerId##
DECLARE @AnswererID int = ##AnswererID##
SELECT a.CreationDate as [DateAsked],
a.ID AS [Post Link],
c.Body AS [Answer],
CASE WHEN a.AcceptedAnswerID = c.ID THEN 'Accepted' ELSE '' END [Status]
FROM Posts a
INNER JOIN Posts c
ON a.ID = c.ParentId
WHERE a.OwnerUserId = @AskerID AND
c.OwnerUserId = @AnswererID AND
a.PostTypeId = 1 AND -- <<== Question
c.PostTypeId = 2 -- <<== Answer
ORDER BY a.CreationDate ASC