DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to get 10 random products using the NEWID function?

Execute the following Microsoft SQL Server T-SQL scripts in Management Studio Query Editor to generate a set of 10 random products at each execution and to generate random numbers:

use AdventureWorks2008;

 

select top 10 Name from Production.Product

order by newid();

/* Name

Half-Finger Gloves, S

Spokes

External Lock Washer 9

Metal Sheet 3.....*/

------------

 

------------

-- Generating Random Numbers with NEWID()

------------

SELECT Random=ABS(CHECKSUM(NEWID())), ProductName=Name

FROM AdventureWorks2008.Production.Product

ORDER BY Random;

/*

Random      ProductName

7933079     Internal Lock Washer 8

13332346    Minipump

23388771    Touring-1000 Blue, 54

30116924    Thin-Jam Hex Nut 3

30398015    Metal Sheet 3

31054093    Thin-Jam Lock Nut 8  ..... */

------------

Related article

http://www.sqlusa.com/bestpractices/newid/

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE