Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 2nd, 2007, 05:43 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting a random range of #'s between 1-37

Hi I am new to SQL and need to insert a random range of #'s between 1-37. I know DECLARE, RAND(), and etc. are involved, but I just can't seem to get my hands around it. So thank you in advance for your assistance.

I basically have a table with 900,000 rows and two columns.
Column 1 and Column 2.
I need all the rows in Column 2 to be randomly numbered 1 through 37.

Thanks again,

JC
 
Old March 5th, 2007, 12:12 PM
Registered User
 
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Never mind, I figured it out.

UPDATE table
SET column2 = 1 + 38*RAND(CHECKSUM(NEWID()))
 
Old March 16th, 2007, 02:03 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

UPDATE table
SET column2 = 1 + CAST(CAST(NEWID() AS BINARY(36)) AS BIGINT) % 37





Similar Threads
Thread Thread Starter Forum Replies Last Post
Single Typo in 'Final' VB Code - causes 37 errors irelandk BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 3rd, 2009 02:30 PM
debug version of 1.37 release? bobarnold BOOK: Beginning Cryptography with Java 1 October 12th, 2007 06:28 PM
Errata, page 37 theoxylo BOOK: Professional Java Development with the Spring Framework 0 December 6th, 2005 06:55 PM
Query to return 37 records maha Access 3 September 10th, 2004 02:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.