Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Display every Nth record.

Total Hit ( 1492)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
--//Script to display every nth record from table
--//Create test table
if OBJECT_ID('myTable') IS NOT NULL
   DROP TABLE myTable
go

create table myTable
(
field1 int
,field2 char(4)
)
go
Insert into myTable(field1,field2) Values(001,'aaaa')
Insert into myTable(field1,field2) Values(101,'bbbb')
Insert into myTable(field1,field2) Values(201,'dfdf')
Insert into myTable(field1,field2) Values(301,'sfsf')
Insert into myTable(field1,field2) Values(401,'dgfg')
Insert into myTable(field1,field2) Values(501,'hjjh')
Insert into myTable(field1,field2) Values(601,'45rf')
Insert into myTable(field1,field2) Values(701,'fhhh')
Insert into myTable(field1,field2) Values(801,'ghhn')
Insert into myTable(field1,field2) Values(901,'gfhh')

go

declare @n int
--/////////////////////////////////////

set @n=3 --//Display every 3rd record

--/////////////////////////////////////

SELECT
  IDENTITY (int, 1, 1) As Rank  --//Generate sequencial number
  ,t.*
INTO #tmp
FROM dbo.myTable t--dbo.tmpRenewNotes

--//Display result
select * from #tmp where rank % @n = 0

drop table #tmp


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.