Solved

SQL Query  get "meddle" records

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need sql in string 2 28
SQL parsing XML works but want to do it another way 4 15
Database Owner 3 12
Applying Roles in Common Scenarios 3 13
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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

680 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