Solved

Update random record

Posted on 2006-12-01
3
203 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now