Solved

Update random record

Posted on 2006-12-01
3
206 Views
Last Modified: 2008-02-01
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())

0
Comment
Question by:wahooo
  • 3
3 Comments
 
LVL 13

Expert Comment

by:Atlanta_Mike
ID: 18056733
Try this

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

Expert Comment

by:Atlanta_Mike
ID: 18056738
Ooops


UPDATE Kalender_svar
    SET dailywinner = 1  
WHERE Id =
    (
        SELECT TOP 1 ID, NEWID()
        FROM Kalender_svar
        ORDER BY 2)
0
 
LVL 13

Accepted Solution

by:
Atlanta_Mike earned 250 total points
ID: 18056750
Finally...

UPDATE Kalender_svar
    SET dailywinner = 1  
WHERE Id =
    (
        SELECT TOP 1 ID
        FROM Kalender_svar
        ORDER BY NEWID())
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question