Python Tag Filtering by print statements (list)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Code Review

Q&A for peer programmer code reviews

--Tag Ids
DECLARE
    @python INT = 3,
    @python_2_6 INT = 1512,
    @python_2_7 INT = 827,
    @python_3_x INT =694;
DECLARE @Question INT = 1;

WITH NoVersionTag AS (
    --Questions tagged with [python]
    SELECT Id
    FROM Posts AS p
    JOIN PostTags AS pt ON p.Id = pt.PostId
    WHERE p.PostTypeId = @Question
    AND p.ClosedDate IS NULL
    AND p.DeletionDate IS NULL
    AND pt.TagId = @python
    --Subtract/except posts tagged with a Python version
    EXCEPT
    SELECT Id
    FROM Posts AS p
    JOIN PostTags AS pt ON p.Id = pt.PostId
    WHERE p.PostTypeId = @Question 
    AND p.ClosedDate IS NULL
    AND p.DeletionDate IS NULL
    AND pt.TagId IN (@python_2_6, @python_2_7, @python_3_x)
)
SELECT
    3 AS [PythonVersion],
    '`print()` function' AS [SearchMethod],
    p.Id AS [PostId],
    p.Id AS [Post Link],
    p.Tags, 
    p.Body
FROM Posts AS p
WHERE p.Id IN (SELECT Id FROM NoVersionTag)
AND p.Body LIKE '%<code>%print(%' --`print()` function
UNION
SELECT
    2 AS [PythonVersion],
    '`print` keyword' AS [SearchMethod],
    p.Id,
    p.Id AS [Post Link],
    p.Tags, 
    p.Body
FROM Posts AS p
WHERE p.Id IN (SELECT Id FROM NoVersionTag)
AND p.Body LIKE '%<code>%print%'      --`print` keyword
AND p.Body NOT LIKE '%<code>%print(%' --NOT `print()` function
ORDER BY PostId

Enter Parameters

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