Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 random issue in Insert statement

Author  Topic 

chih
Posting Yak Master

154 Posts

Posted - 2007-05-02 : 22:08:47
Hi everyone,

I would like to insert random character.
for example,

insert into tmp (userid,code)
select userid,'b'+char(97+25*rand())+char(97+25*rand())
from list

But all radnom character is the same. I think it's becasue insert statement. Is there a way to solve it? (I don't want to use cursor).

Thx

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-05-02 : 23:42:02
Search for 'random number" in this forum...u find so many topics discussed and will be helpful for u.
Go to Top of Page

chih
Posting Yak Master

154 Posts

Posted - 2007-05-03 : 00:17:59
I have no problem in generating random character. but when I insert them to table, all value of code are the same
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-03 : 00:39:03
Make use of F_RANDOM_INTEGER() function on the following link instead of using built-in RAND() function:
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=69499[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -