473,378 Members | 1,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

generate a random int to add to a record

I need to generate a random whole number between 0 and 999 to add to
add to every record in a table. The number needs to be different for
each record in the table.

How would I do this all within TSQL?
Jul 20 '05 #1
1 6522
the procedure of mystery man produces random numbers but they can
appear more than once which should not happen. So it would be
necessary to create a new number, check if it exists, if not use it,
else create a new random number, ... can become a timeconsuming
problem if you try this with numbers between 1 and 999 and you have
more than 999 records in your database :-))
If you only need it to do a random read, try this:

select * from myTable order by newid()

this will show you the records every time in another order.

hth,
Helmut

"Mystery Man" <Pr************@hotmail.com> schrieb im Newsbeitrag
news:87************************@posting.google.com ...
Have a look at the Rand function.

Here is a possible example

declare @counter int
SET @counter = 1
WHILE @counter < 1000
begin
print convert(int,substring(convert(varchar(8), RAND(@counter)),6,3))
SET @counter = @counter + 1
end

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
2
by: Ini | last post by:
Hi, Is there an easy way to pick at random one record out of a recordset and then leave this recordset? I was thinking about doing a recordcount of the recordset, then find at random the...
15
by: John Cassidy | last post by:
This has been driving me crazy. I've done basic C in school, but my education is mainly based on object oriented design theory where Java is our tool. For some reason, while helping a friend with a...
2
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
9
by: MyInfoStation | last post by:
Hi all, I am a newbie to Python and would like to genereate some numbers according to geometric distribution. However, the Python Random package seems do not have implemented functionality. I am...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
20
by: jjmillertime | last post by:
I'm new so i apologize if this is in the wrong spot. I'm also new to programming in C and i've been searching for quite a while on how to create a program using C that will generate two random...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.