473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

nth subset of data from current table

Hi,

I was wondering if you guys have any nth script to reads from table
and outputs into a temp table subset of records. There was a nth tool
I used to use it was GROUP1 which was written in C and it used to be
very fast on nth -in a flat file. In this program we used to pass few
paramaeters. For example if I want 30,000 records from the file of
500,000. The function seams to work something like this. you divide
the 30,000 records of 500,000 which will result with .090909090909.
Now we would pass only the first 7 digit (0909090) as parameter that
would nth the file down to 30,000 records. This function allways
worked whichever number you use as long as the read file is larger
than output file
I like to use the similar concept in Sql Server and I was wondering if
anyone has any script to do this or how to go about this?

Thank you. I appreciate your feedback
agron
Jul 20 '05 #1
1 1424
I assume this is sampling for the purposes of generating test-data or
something similar? As we know, tables have no inherent order so this only
makes sense if you have some column that defines a unique, numeric sequence.
If you have such a column then you can use the modulo operator to sample
from it:

SELECT *
FROM YourTable
WHERE col % @m = 0

where @m = (total number of rows) / (required sample size)

Usually however, it's more convenient just to take a random sample of N rows
like this:

SELECT TOP 1000 *
FROM YourTable
ORDER BY NEWID()

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Neville | last post by:
The solution to my dilemma seems straight-forward, yet my mind has not been forthcoming with a direct route. My Project form has a tab control with multiple sub-forms; these distinct sub-forms...
3
by: Carolyn Vo | last post by:
I have a datagrid in my web control class that I am trying to get the current rows displayed for. I have enabled paging on the datagrid so if the user is currently on page 3 of 8, and if I have...
9
by: Annalyzer | last post by:
This should be an easy one, but I can't figure it out. frmProvider (data source: tblProvider) displays information about child care providers. Since tblProvider is fairly large, I am using a...
4
by: Andrus | last post by:
Checking Client-only framework subset in VS2008 SP1 project properties causes in my application compile error The type 'System.Data.Linq.ITable' is defined in an assembly that is not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.