Help with query

Hello

I am sure this is a relatively easy one for you guys.
I need to select some random records using the following criteria

First I need to count the files that were closed last month. I have a closed date. This number will be X
Then I want to take X and divide that number by 20, this number will be Y
Then I want to run a counter down my table, resetting at Y.
Then I will pull out all rows where the counter = 1

Does this make sense, and what is the easiest way of tackling the task as I have been exporting chunks of data and manually manipulating the files, but ideally I shouldn't be that involved in the selection

thanks
BananaFuryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Two things:
Give us a data mockup, both sample data and expected output, of what you're trying to pull off here.  The description is not very intuitive.
I recommend renaming this question to something more descriptive of what the question is, as 'Help with Query' is not going to attract all experts that can answer your question, and doesn't help future experts searching for their own answers.

Thanks in advance.
0
ste5anSenior DeveloperCommented:
hmm, how should that work at all: I need to select some random records using the following criteria??
0
Scott PletcherSenior DBACommented:
DECLARE @x int --count of total rows

SELECT derived.*
FROM (
    SELECT *, ROW_NUMBER() OVER(ORDER BY NEWID()) AS row_num
    FROM table_name
) AS derived
WHERE row_num % @x = 1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BananaFuryAuthor Commented:
Thanks very much for your help, most appreciated!
0
ste5anSenior DeveloperCommented:
???

SELECT TOP 10 PERCENT *
FROM	sys.objects
ORDER BY NEWID();

SELECT derived.*
 FROM (
     SELECT *, ROW_NUMBER() OVER(ORDER BY NEWID()) AS row_num
     FROM sys.objects
 ) AS derived
 WHERE row_num % 10 = 1 

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.