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
 SQL Server Administration (2005)
 Random Unique Number generator

Author  Topic 

VxChemical
Starting Member

4 Posts

Posted - 2012-02-15 : 03:52:00
I have a table with a long list of people, and one of the columns is a LocalIDNumber, some of the rows have a 8 digit number it, but some has NULL.

What i need to do is, fill out the ones that has NULL and give them a unique 8 digit number.

Is there a great and easy way to generate the numbers with an Sql Query.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-15 : 04:33:06
use this F_RANDOM_INTEGER


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

VxChemical
Starting Member

4 Posts

Posted - 2012-02-15 : 05:00:14
Hey thanks for the response.

I am really new to everything SQL, so if it was at all possible i would like a hand to adapt the script to my situation if you dont mind helping.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-15 : 05:58:33
[code]
update yourtable
set LocalIDNumber = dbo.F_RANDOM_INTEGER(10000000, 99999999, newid())
where LocalIDNumber is null
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

VxChemical
Starting Member

4 Posts

Posted - 2012-02-15 : 07:03:07
quote:
Originally posted by khtan


update yourtable
set LocalIDNumber = dbo.F_RANDOM_INTEGER(10000000, 99999999, newid())
where LocalIDNumber is null



KH
[spoiler]Time is always against us[/spoiler]





Im sorry for being a complete ignorant, but i get an

Invalid object name `dbo.F_RANDOM_INTERGER`.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-15 : 07:13:12
get it from the link in my post at 02/15/2012 : 04:33:06


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

VxChemical
Starting Member

4 Posts

Posted - 2012-02-22 : 03:02:49
So do i run the info in your post as a Query Analyzer?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-22 : 03:13:38
yes


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -