DECLARE @datefrom datetime = '2012-01-01 00:00:00' DECLAR...

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

DECLARE @datefrom datetime = '2012-01-01 00:00:00'
DECLARE @dateto datetime = '2012-12-31 12:59:59'
SELECT Users12.Id, ROW_NUMBER() OVER(PARTITION BY Users12.Id ORDER BY Badges.Date ASC), Badges.Name
FROM (
  SELECT TOP 187 Users.Id
  FROM Users
  WHERE Users.CreationDate BETWEEN @datefrom AND @dateto
  ORDER BY NEWID()
) AS Users12, Badges
WHERE Users12.Id = Badges.UserId
AND Badges.TagBased = 0
ORDER BY Users12.Id, Badges.Date

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results