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
 General SQL Server Forums
 New to SQL Server Programming
 Bulk inserting random codes

Author  Topic 

dmeagor
Starting Member

16 Posts

Posted - 2010-06-06 : 14:34:18
Hi

I need to select some records and reinsert/duplicate them again (not replace them) with a set of 8 digit random codes (a-z/A-Z/0-9) (not necessary to be unique.)

This is what I am trying to do...

INSERT INTO tblExample(fname,sname,email,code) SELECT fname,sname,email,generateCode() From tblExample WHERE id=12345

Does anyone know how to do this? I've found several examples that generate a single code but I can't seem to put them into this query.

David Meagor

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-06 : 16:32:10
You'll be fine if the function is a scalar function and returns one value per record.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

naveengopinathasari
Yak Posting Veteran

60 Posts

Posted - 2010-06-07 : 03:50:33
Use Rand() function to generate numbers
if you require alphabets to be genereated, convert the random number to char.

Lets unLearn
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-07 : 03:56:38
See if these help
http://beyondrelational.com/blogs/madhivanan/archive/2007/11/20/random-password-generator.aspx
http://beyondrelational.com/blogs/madhivanan/archive/2009/03/27/filling-random-passwords-set-based-approach.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -