Comments on answers by user mentioning specific phrases

1

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

DECLARE @phrase1 AS NVARCHAR(60) = ##Phrase1:string?thank##;
DECLARE @phrase2 AS NVARCHAR(60) = ##Phrase2:string? ##;
DECLARE @phrase3 AS NVARCHAR(60) = ##Phrase3:string? ##;
DECLARE @username AS NVARCHAR(60) = ##DisplayName:string? ##;
DECLARE @userId AS INT = ##UserId:int?-1##;

WITH Answers AS (
  SELECT Id, OwnerUserId
  FROM Posts
  WHERE PostTypeId = 2
    AND (@userId < 0 OR OwnerUserId = @userId)
    AND (@username = '' OR OwnerUserId IN (
        SELECT Id
        FROM Users
        WHERE DisplayName = @username))
)
SELECT TOP ##Limit:int?100##
  a.OwnerUserId AS [User Link],
  a.Id AS [Post Link],
  c.Id AS [Comment Link],
  c.CreationDate AS [Comment Date]
FROM Answers a
  INNER JOIN Comments c ON a.Id = c.PostId
WHERE 
  (@phrase1 = '' OR LOWER(c.Text) LIKE '%' + @phrase1 + '%')
  AND (@phrase2 = '' OR LOWER(c.Text) LIKE '%' + @phrase2 + '%')
  AND (@phrase3 = '' OR LOWER(c.Text) LIKE '%' + @phrase3 + '%')
ORDER BY CreationDate DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results