Has a user voted to something in the last N months?

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

-- uid: User ID
-- NbMonth: Number of months

DECLARE @user INT = ##uid:INT##
DECLARE @N INT = ##NbMonth:INT##
-- 

IF ( (SELECT TOP 1 DATEDIFF(MONTH,GETDATE(),v.CreationDate) AS 'Date'
      FROM Votes v WHERE v.UserId = @user ORDER BY 'Date' DESC) < -@N)
    SELECT 'No';
ELSE
    SELECT 'Yes';

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results