0

I am new to T-SQL and would greatly appreciate help on the following query on the Stack Exchange Data Explorer.

For a given comment I need to display the username and reputation of whoever posted the comment, and whoever posted the post that was commented on. For instance, comment 5245510:

Why not using isnan() from math.h? Any specially reason?

The result would be similar to:

commenter username   reputation   poster username   reputation 
Constantin           2,474        kp11              419

1 Answer 1

2

Here is the query:

SELECT
  CASE WHEN U.Id = P.OwnerUserId THEN 'Poster' ELSE 'Commenter' END AS [User],
  U.Id AS [User Link],
  U.Reputation AS [User Rep]
FROM Comments AS C
INNER JOIN Posts AS P
  ON P.Id = C.PostId
INNER JOIN Users AS U
  ON U.Id IN (P.OwnerUserId, C.UserId)
WHERE C.Id = ##CommentId:int##

Link: https://data.stackexchange.com/stackoverflow/query/180387/name-and-rep-of-commenter-and-op-for-comment-id

Enter the comment ID in the box near the Run Query button.

2
  • Usually you can have a user-input parameter like this: DECLARE @CommentId int = ##InputId## which will add an input box to the query. In this case, I get an error when I try to save it. Which is odd and shouldn't happen.
    – jmac
    Apr 3, 2014 at 4:49
  • @michaelb958 Sorry to bug you with this, but is it possible to give a specific set of values(comment IDs) to this SQL query? how could I select the user name tagged in that specific comment to print the tagged user ID's reputation and user-name. Apr 5, 2014 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .