Solved

SQL Query  get "meddle" records

Posted on 2016-08-11
2
58 Views
Last Modified: 2016-08-11
I have a query that can return from 0 to 50 records

SELECT  CampaignID , CampaignCount FROM    MyQuery

I would like to select on that list where ROW_NUMBER() > 5
And select the next 5 records and run an update on them

Update Campaigns
Set vendorserver = 1 where CampaignID IN (Select CampaignID from queryresults)
0
Comment
Question by:lrbrister
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 41752218
Replace ?? with whatever logic you mean by ROW_NUMBER

SELECT CampaignID, CampaignCount
FROM (
   SELECT  CampaignID , CampaignCount, 
       ROW_NUMBER () OVER (PARTITION BY ?? ORDER BY ??) as row_no
   FROM    MyQuery ) a
WHERE a.row_no > 5 AND a.row_no <= 10 

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 41752384
Thanks
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

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

861 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