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 2008 Forums
 Transact-SQL (2008)
 Random ID

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-04-12 : 22:25:54
Hello,

I have a table name Test with columns ID and Value.
My ID will be a NVarChar with 8 characters length from:
"abcdefghijklmnopqrstuvxyz0123456789"

How can I create an SQL function that creates a Random ID?
And if possible providing the length of the ID and the allowed characters as inputs?

Of course the ID generated should not exist in table Test.

Thanks,
Miguel

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-13 : 03:14:36
Play with this
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/20/random-password-generator.aspx

Madhivanan

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

- Advertisement -