Q&A for professional robotic engineers, hobbyists, researchers and students
DECLARE @X INT = 4500584; SELECT U.ID USER_ID,P.ID ACTIVITY_ID, YEAR(P.CREATIONDATE) CREATION_DATE, 'POST' ACTIVITY_TYPE FROM USERS U INNER JOIN POSTS P ON U.ID=P.OWNERUSERID WHERE U.ID=@X AND P.CREATIONDATE >= U.CREATIONDATE UNION ALL SELECT U.ID USER_ID,C.ID ACTIVITY_ID, YEAR(C.CREATIONDATE) CREATION_DATE, 'COMMENT' ACTIVITY_TYPE FROM USERS U INNER JOIN COMMENTS C ON U.ID=C.USERID WHERE U.ID=@X AND C.CREATIONDATE >= U.CREATIONDATE UNION ALL SELECT U.ID USER_ID,V.ID ACTIVITY_ID, YEAR(V.CREATIONDATE) CREATION_DATE, 'VOTE' ACTIVITY_TYPE FROM USERS U INNER JOIN VOTES V ON U.ID=V.USERID WHERE U.ID=@X AND V.CREATIONDATE >= U.CREATIONDATE UNION ALL SELECT U.ID USER_ID,SEV.ID ACTIVITY_ID, YEAR(SEV.CREATIONDATE) CREATION_DATE, 'SUGGESTEDEDITVOTES' ACTIVITY_TYPE FROM USERS U INNER JOIN SUGGESTEDEDITVOTES SEV ON U.ID=SEV.USERID WHERE U.ID=@X AND SEV.CREATIONDATE >= U.CREATIONDATE;