Q&A about the site for music historians, critics, and fans
-- Parameters DECLARE @FromDate DATETIME = '2018-01-01'; DECLARE @ToDate DATETIME = '2022-01-01'; DECLARE @TagName NVARCHAR(255) = 'javascript'; DECLARE @RowCount INT = 50; -- Adjust the number of rows as needed -- Temp table to store results CREATE TABLE #TempResults ( PostId INT, PostTitle NVARCHAR(MAX), PostText NVARCHAR(MAX), Tags NVARCHAR(MAX), AnswerCount INT, ); -- Insert into the temp table directly using TOP INSERT INTO #TempResults (PostId, PostTitle, PostText, Tags, AnswerCount) SELECT TOP (@RowCount) Id AS PostId, Title AS PostTitle, Body AS PostText, Tags, AnswerCount FROM Posts WHERE PostTypeId = 1 AND CreationDate BETWEEN @FromDate AND @ToDate AND Tags LIKE '%' + @TagName + '%' ORDER BY CreationDate DESC; -- Select the desired columns SELECT PostId, PostTitle, PostText, Tags, AnswerCount FROM #TempResults; -- Drop the temp table DROP TABLE #TempResults;