Comments by user mentioning specific phrases

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

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

SELECT TOP ##Limit:int?100##
  c.Id AS [Comment Link],
  c.Text,
  c.Score,
  c.CreationDate AS [Comment Date]
FROM Comments c
WHERE 
  UserId = @userId
  AND (@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