Extract accepted and most-voted answer of a question

0

Please login or register to vote for this query.

(click on this box to dismiss)

Tridion

Q&A for Tridion developers and administrators

SELECT Id AS [Post Link], Body, Score
FROM (
    SELECT TOP 1 Id, Body, Score, DENSE_RANK() OVER(ORDER BY Score DESC) Rank 
    FROM (
        SELECT p.Id, p.ParentId, p.Body, p.Score
        FROM Posts p 
        WHERE p.ParentId IN (34583717, 34604646, 34698074, 34754012, 35373007, 35381287, 35383091, 35522452, 35527655, 35817325, 35998830, 36006029, 36205285, 36741334, 36750201, 37981820, 37992225, 38034789, 38065638, 39153149, 39179068, 39361909, 39397548, 39681163, 39698069, 39717409, 39776414, 40309682, 40379550, 40468739, 40651561, 41401312, 41614259, 42056406, 42077532, 43131335, 43211850, 44280736, 44324080, 44738609, 44850725, 45600622, 45631800, 45849593, 45867402, 45884704, 46358013, 46488969, 46591815, 46617942, 46829131, 47493674, 47882189, 48175467, 48351332, 48395523, 49828745, 50002149, 50204844, 50852226, 51082984, 51277788, 51486554, 52572574, 52752675, 54973061, 56510212, 56982292, 57628890, 57676859, 58037309, 59168380, 59184816, 59590110)
 
    )x
    ORDER BY Rank ASC
)x

UNION
SELECT * 
FROM (
    SELECT Id, Body, Score
    FROM (
        SELECT a.Id, a.ParentId, a.Body, a.Score FROM Posts a 
        WHERE a.ParentId = ##QuestionId##
    )x
)x 
WHERE (SELECT b.AcceptedAnswerId FROM Posts b WHERE b.id = ##QuestionId##) = id

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results