Solved

Update random record

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
This query failed in sql 2014 5 30
Query Syntax 17 34
Inserting oldest record into new table. 5 23
SQL - Use results of SELECT DISTINCT in a JOIN 4 17
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

770 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