Search  Search    
    
News, IT news, free tutorials, photos, graphics, Flash advertising solutions, logos design, banners design, free e-books, free icons, wallpapers, CD presentation, DVD presentation, Web design.
Microsoft SQL Server - How to select several random records from a table.
  More SQL server database tutorials ... 

 

Complete guide for Euro 2012’, about 300 hundred pages filled with comprehensive information about Euro 2012


Euro 12 - teams, managers, players, fixtures, referees, the brand new ‘Tango 12’ Adidas ball and much, much more. Few hundreds amazing photos.


E-books, free e-books, Euro 2012 e-books


Auckland events in photos at bonanz.com


1 500 photos of fun-run 'Ports of Auckland Round the Bays 2012' at bonanz.com


Ocean swim - more than 1 500 photos of State King of the Bays

 

SoftFern.com Forums BonaNZ.com forums

 

SoftFern.com Forums - articles, news, links   

 

BonaNZ.com Forums - articles, news, links   


Photos of State King of the Bays event at bonanz.com


‘Complete guide for Euro 2012’: Given profile all 368 footballers with their photos.
 
 cWeb design, Software development, Graphics, Design Logo, Banners, DVD/CD presentation
 


‘Complete guide for Euro 2012’: Read about star players of each squad. Find out who is the key player of each team. What Pele expects of Euro 2012?



‘Complete guide for Euro 2012’: Compare annual salary of coaches participating in the Euro-2012 - and how it happened that the team of the most paid coach finished the last in their group?




‘Complete guide for Euro 2012’: Euro 2012 footballers: who are the most expensive players? Who are the Rising stars at Euro 2012?





E-books, free e-books, Euro 2012 e-books
 
  
 Popularity 
 Rating: 3.6      Rate this article   65 
 14 Dec 2011

Microsoft SQL Server - How to select several random records from a table.

 







Sometimes it is necessary to select several random records from a database.

This task can be achieved by using built-in function NEWID() using TOP clause and ORDER BY clause.

Suppose you have a table SoftFernNews from which you want to select 10 random rows containing Titles and IDs every time when user visits your home page.

Solution.

The stored procedure looks as following:

ALTER PROCEDURE dbo.SelectRandom
AS SELECT TOP 10 NewsID, NewsTitle
FROM dbo.SoftFernNews
ORDER BY NEWID()

After executing the stored procedure, the result was:
First time:

NewsID NewsTitle
162 Al-Qaeda's number two leader, was killed in Pakistan on 22 August.
203 Rock in Rio festival
100 Inspection of electronics shops for fake Apple Stores
107 Birds made from amethyst, onyx....
170 British massively stocked with Baseball Bats, Police Telescopic Tonfa etc.
85 Kinect for Windows SDK
184 About Blizzard Entertainment - I
113 Mike Tyson - a nurse.
250 Fantastic vertical gardens, part II
217 Skype is officially now part of Microsoft

Second time:
NewsID NewsTitle
107 Birds made from amethyst, onyx....
207 RWC 2011, the latest results and the Quarter Finals
240 Toyota robots – domestic robot
296 Muhammad Ali was taken to hospital
110 Amazing ads
221 Microsoft’s Skype Deal: Winners and Losers
128 Beautiful landscapes part III.
144 Why Google’s purchased Motorola Mobility?
279 Horrifying tricks from extreme artist.
159 Street Art – incredible illusions. Part I

Third time:
NewsID NewsTitle
161 Martial art champion ‘Black Tiger’ strikes to death.
96 Corrida - some photos
240 Toyota robots – domestic robot
242 More about robots – II
287 iPhone 4S expenses
148 Go swimming at the Auckland during winter time. Part II
193 Hollywood stars tattoos
184 About Blizzard Entertainment - I
86 Fake Chinese Apple store
293 Euro 2012 draw occurred

As you can see, every time it selected some random records.








More similar topics with SQL tips:

Oracle database - How to select several random records from a table

Database DB2 - How to select several random records from a table

MySQL database - How to select several random records from a table

PostgreSQL - How to select several random records from a table

Microsoft SQL Server - How to select several random records from a table


  
  More similar links:

Oracle database - How to select several random records from a table.

PostgreSQL - How to select several random records from a table.

Sparse Columns in SQL Server 2008

Adding and Remowing Connections to Microsoft SQL server

Microsoft SQL Server - How to select several random records from a table.

Alter Table, Alter Column in MS SQL Server 2008

Database DB2 - How to select several random records from a table.

 
    
 Rate this article from 1 to 5 

      Comments
         
 

11.07.2012    Michael

SQL can execute qiurees against a database, retrieve,update,insert data from a database and empty refer to an empty result of no rows and NULL refer to a table with one row holding a NULL value.


12.07.2012    eljulp

7GbQyq , [url=http://irxmoludgdap.com/]irxmoludgdap[/url], [link=http://olhvohhfvkqb.com/]olhvohhfvkqb[/link], http://ogxfgfljtdsn.com/


14.07.2012    ydoyyxprdzq

DBILGp , [url=http://jpyjheisnhvq.com/]jpyjheisnhvq[/url], [link=http://evxzwipojqbx.com/]evxzwipojqbx[/link], http://onezpngpkmyj.com/


05.01.2013    Arah

Rob,Just a follow-up on the two potsed feedbacks. Do you use Full-Text Search (FTS)? Indexing Service or SQL Server 2000 FTS?I'd ask you whether you can solicit some of the search engines to take .aspx extensions seriously . While I suspect that you

         
        Add comment
Your name:
Your comment:
                      
 Tags: SoftFern Tutorials, SoftFern Microsoft Office Tutorials, SoftFern Programming Tutorials, database, SQL server, SQL tips, stored procedures, Microsoft SQL server tips, SQL server solutions, SQL databases solutions, SQL, DB2, table, Database DB2, select random records, Microsoft SQL server
   More SQL server database tutorials ...
News, IT news, free tutorials, photos, graphics, Flash advertising solutions, logos design, banners design, free e-books, free icons, wallpapers, CD presentation, DVD presentation, Web design.  
Home - News  - Tech news - News football - Sport news - Health & Beauty - Misc news
Photoshop and Photography tutorials - iPad, Androids, Tablet PCs - Programming - Windows
- Microsoft Office - Misc tutorials- Site Map Control Panel - Site Map Grid
- Add Link - Links Exchange - Our Portfolio - Samples web sites   Archive of news and tutorials

SoftFern (New Zealand LTD). 
Design and development by SoftFern 2003 - 2010 Graphics supplied by BonaNZ.com