Wednesday, February 08, 2012    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< May 2006 >>
S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

Categories
 • Acrobat (5) [RSS]
 • Adobe (110) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (34) [RSS]
 • AdobeMAX11 (27) [RSS]
 • AIR (297) [RSS]
 • Appearances (217) [RSS]
 • Books (86) [RSS]
 • CFEclipse (15) [RSS]
 • Cloud (1) [RSS]
 • ColdFusion (1477) [RSS]
 • ColdFusion Builder (22) [RSS]
 • Data Services (42) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (356) [RSS]
 • Flex (562) [RSS]
 • Home Automation (5) [RSS]
 • HTML5 (22) [RSS]
 • JavaScript (2) [RSS]
 • Jobs (130) [RSS]
 • jQuery (14) [RSS]
 • JRun (14) [RSS]
 • Labs (62) [RSS]
 • LiveCycle (37) [RSS]
 • MAX (284) [RSS]
 • Mobile (239) [RSS]
 • Regular Expressions (19) [RSS]
 • RIA (21) [RSS]
 • SQL (45) [RSS]
 • Stuff (554) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (167) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Day : May 26, 2006 / Main
May 26, 2006

Using TABLESAMPLE To Retrieve Partial Resultsets

I just discovered a new SELECT clause that has been added to T-SQL in SQL Server 2005. TABLESAMPLE can be used to return a sampling of rows (either a fixed number or a specified percent of the table rows). Here is how it is used:

/* Get a sample 5 rows */
SELECT *
FROM table
TABLESAMPLE (5 ROWS)

/* Get a sample 10 percent of rows */
SELECT *
FROM table
TABLESAMPLE (10 PERCENT)
It is worth noting that you may not get the exact number of rows that you'd expect. Sampling occurs by table page, and the number of rows in a page can vary.

Comments
Another new function they added and I find really cool is that you can now use TOP with a DELETE.
# Posted By tof | 5/28/06 7:51 PM
As a point of reference in SQL 2000 you can do this with the newid() function.

select top 5 *
from table
order by newid()
# Posted By intj | 5/30/06 11:34 AM
Well, Tablesample is a great sampling method.

But I could not get it working with table variable.

Here is the TSQL

declare @test table
(
id int identity(1,1),
test_count int
)

insert into @test values(1)
insert into @test values(2)
insert into @test values(3)
insert into @test values(4)
insert into @test values(5)
insert into @test values(6)
insert into @test values(7)
insert into @test values(8)
insert into @test values(9)
insert into @test values(10)
insert into @test values(11)

select * from @test tablesample(10)

select * from @test tablesample(5 rows)

select * from @test tablesample(40 percent)

Nothing works!
# Posted By abhi | 8/3/07 5:40 PM

  © Copyright 1997-2009 Ben Forta, All Rights Reserved