Posted by: R Manimaran | July 4, 2008

Inserting Random Values into SQL SERVER Table

Inserting Random numbers into a Table Column

We may have a situation to insert some random numbers into our table. For that purpose we can use the Rand() Function which is available in SQL SERVER.

Example:

Set noCount on

— Declare a Table

Declare @Table1 Table(id int,Rndvalue int)

Declare @index int

select @index=1

— insert 10 Random values into the Table

while @index<11

Begin

–Generate Random Values

Insert into @Table1 values(@index,ceiling(1000*Rand()))

–Increment the id value

Select @index=@index+1

end

—-Select the values

Select id,RndValue from @Table1

—–Output

Random Values insertion

Random Values insertion

Advertisements

Responses

  1. awesome.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: