Where did we meet?

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

-- This query displays the questions where the two users meet.

-- It requires two paramaters: 
--     @AskerID     => the one who raised the question
--     @AnswererID  => the one who answered

-- It will also displays whether the answer has been accepted or not.

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

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached