Solved

SQL Query  get "meddle" records

Posted on 2016-08-11
2
38 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

760 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

20 Experts available now in Live!

Get 1:1 Help Now