This is probably a very simple question, but my attempts to find the answer prevented Google from finding answers that showed how to reuse the request, creating a stored procedure instead. I want to reuse the query results inside a stored procedure.
Here is an example of cutting, where I cut NOCOUNT, XACT_ABORT, TRANSACTION, TRYand most of the logic.
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
What is the syntax for reusing duplicate nested results SELECTinstead of doing it twice?
source
share