December 6, 2005 at 10:42 am
I'm trying to generate a unique 8 digit password for my users, and this is something simple I could come up with. however, this would only work if every record was in tact, and no missing ID's. Any suggestions on how I could recode this?
declare @cnt smallint
declare @counter smallint
set @counter = 1
set @cnt = (select count(*) from users)
while @counter < @cnt
begin
update users set Password=left(replace(reverse(rand()),'.','0'),8) where id=@counter
set NOCOUNT ON
set @counter = @counter + 1
set NOCOUNT OFF
end
go
December 6, 2005 at 1:28 pm
declare @cnt smallint
declare @counter smallint
set @counter = select min(id) from users
set @cnt = (select max(id) from users)
while @counter is not null
begin
update users set Password=left(replace(reverse(rand()),'.','0'),8) where id=@counter
set NOCOUNT ON
set @counter = null
set @counter = min(id) from users where id > @counter
set NOCOUNT OFF
end
go
Regards,
gova
December 6, 2005 at 10:35 pm
update users set Password=left(NEWID(),8)
Andy
December 7, 2005 at 6:20 am
hah ha Why didn't I thing about that.
Regards,
gova
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply