Solved

Update random record

Posted on 2006-12-01
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

752 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