Link to home
Start Free TrialLog in
Avatar of wahooo
wahooo

asked on

Update random record

I have a table that handles a competition where I want to pick one winner every day (make it as a daily job running on the SQL-server)

How can I make a query that solves this: If I have a table witt all the answers and one column named dailywinner (If 1 = winner)

I tried this but it updates all the records..

Update dbo.Kalender_svar
Set dailywinner = 1  
where  exists (
Select Top 1 dailywinner
FROM         dbo.Kalender_svar
WHERE     (Dag + 1 = DATEPART(d, GETDATE()))
ORDER BY NEWID())

Avatar of Atlanta_Mike
Atlanta_Mike

Try this

UPDATE Kalender_svar
    SET dailywinner = 1  
WHERE Id =
    (
        SELECT TOP 1 ID, NEWID()
        FROM LoanBase
        ORDER BY 2)
Ooops


UPDATE Kalender_svar
    SET dailywinner = 1  
WHERE Id =
    (
        SELECT TOP 1 ID, NEWID()
        FROM Kalender_svar
        ORDER BY 2)
ASKER CERTIFIED SOLUTION
Avatar of Atlanta_Mike
Atlanta_Mike

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial