Q&A for programmers
-- This query displays the questions where the two users meet.
-- It accepts two paramaters:
-- @AskerID => the 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.Title AS [Question],
c.Body AS [Answer],
CASE WHEN a.AcceptedAnswerID = c.ID THEN 'Accepted' ELSE '' END [Status]
FROM Posts a
INNER JOIN PostTypes b
ON a.PostTypeId = b.ID AND b.ID = 1
SELECT aa.ParentId, aa.Body, aa.OwnerUserId, aa.ID
FROM Posts aa
INNER JOIN PostTypes bb
ON aa.PostTypeId = bb.ID AND bb.ID = 2
WHERE aa.OwnerUserId = @AnswererID
) c ON a.ID = c.ParentId
WHERE a.OwnerUserId = @AskerID
ORDER BY a.CreationDate ASC