Q&A for committed Christians, experts in Christianity and those interested in learning more
; with commentsquestions_cte as ( SELECT q.Id AS qId, c.Id AS cId, c.Text AS cText, c.UserId as cOwner, c.CreationDate AS cDate, q.Body AS qBody FROM Posts q INNER JOIN Posts a ON (a.ParentId=q.Id) INNER JOIN Comments c ON (c.PostId=a.Id) UNION SELECT q.Id AS qId, c.Id AS cId, c.Text AS cText, c.UserId as cOwner, c.CreationDate AS cDate, q.Body AS qBody FROM Posts q INNER JOIN Comments c ON (c.PostId=q.Id AND q.PostTypeId=1) ) --- the pairs Comments.Id and Questions.Id --- where comment is posted anywhere on the page --- (comment to the question or to any of the answers) SELECT TOP(##num?50##) cId AS [Comment Link], cText, cOwner AS [User Link], cDate FROM commentsquestions_cte WHERE (cText LIKE '%[^\]\##text?\C##[^a-zA-Z]%') AND NOT ((cText LIKE '%\newcommand{\##text##}%') OR (cText LIKE '%\DeclareMathOperator{\##text##}%') OR (cText LIKE '%\def\##text##%')) AND ((qBody LIKE '%\newcommand{\##text##}%') OR (qBody LIKE '%\newcommand\##text##%') OR (qBody LIKE '%\newcommand{##text##}%') OR (qBody LIKE '%\DeclareMathOperator{\##text##}%') OR (qBody LIKE '%\DeclareMathOperator{##text##}%') OR (qBody LIKE '%\DeclareMathOperator\##text##%') OR (qBody LIKE '%\def\##text##%')) ORDER BY cDate DESC