Skip to content

Instantly share code, notes, and snippets.

@chadcooper
Created January 19, 2014 13:38
Show Gist options
  • Save chadcooper/8505127 to your computer and use it in GitHub Desktop.
Save chadcooper/8505127 to your computer and use it in GitHub Desktop.
-- All my answers
-- All my answers on the site
DECLARE @UserId int = ##UserId##
DECLARE @Year int = ##Year##
SELECT
a.Id AS [Post Link],
CASE WHEN q.AcceptedAnswerId=a.Id THEN 'Accepted' END AS Accepted,
CASE WHEN q.OwnerUserId=a.OwnerUserId THEN 'Self' END AS Self,
a.Score,
a.CreationDate,
CASE WHEN q.CommunityOwnedDate IS NOT NULL THEN 'Q'
WHEN a.CommunityOwnedDate IS NOT NULL THEN 'A' END AS CW
FROM
Posts q
INNER JOIN
Posts a ON q.Id = a.ParentId
WHERE
a.OwnerUserId = @UserId
AND
a.PostTypeId = 2
AND
Year(q.CreationDate) = @Year
ORDER BY
a.Score DESC, a.CreationDate DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment