Solved

SQL Query  get "meddle" records

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

914 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

18 Experts available now in Live!

Get 1:1 Help Now