Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles
DECLARE @UserId INT = '##UserId:INT##'; DECLARE @Year INT = '##Year:INT?-1##'; SELECT @Year = IIF(@Year = -1, YEAR(CURRENT_TIMESTAMP), @Year); SELECT c.Id, c.PostId, c.Score, c.Text, c.CreationDate FROM Comments c WHERE c.UserId = '##UserId##' AND YEAR(c.CreationDate) = @Year --AND c.CreationDate >= '2018-01-01' --AND c.CreationDate < '2019-01-01' --!!! ORDER BY c.CreationDate;