Reuse results of SELECT query inside a stored procedure
<p>This is probably a very simple question, but my attempts to search for an answer are thwarted by Google finding answers showing how to reuse a query by making a stored procedure instead. I want to reuse the results of a query inside a stored procedure. </p>

<p>Here's a cut-down example where I've chopped out <code>NOCOUNT</code>, <code>XACT_ABORT</code>, <code>TRANSACTION</code>, <code>TRY</code>, and much of the logic.</p>

<pre class="lang-sql prettyprint-override"><code>CREATE PROCEDURE Do_Something
    @userId UNIQUEIDENTIFIER
AS
BEGIN

    DELETE FROM LikedItems
    WHERE likedItemId IN
    (
        SELECT Items.id FROM Items
        WHERE Items.userId = @userId
    )

    DELETE FROM FollowedItems
    WHERE followedItemId IN
    (
        SELECT Items.id FROM Items
        WHERE Items.userId = @userId
    )

END
</code></pre>

<p>What is the syntax to reuse the results of the duplicated nested <code>SELECT</code> rather than doing it twice?</p>