Solved

SQL Query  get "meddle" records

Posted on 2016-08-11
2
63 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
[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
2 Comments
 
LVL 66

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

627 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