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
 Update Multiple rows with variable from column

Author  Topic 

stegothdump
Starting Member

9 Posts

Posted - 2012-01-16 : 10:34:33
Hey There,

I've written the following SQL query

DECLARE @HashThis NVARCHAR(MAX)
DECLARE @NewPassword NVARCHAR(MAX)
DECLARE @Salt NVARCHAR(MAX)


EXEC dbo.sp_GenerateRandomString 8, @salt OUTPUT
SELECT @HashThis = Password FROM RegisteredUsers
SELECT @NewPassword = SUBSTRING(UPPER(master.dbo.fn_varbintohexstr(HASHBYTES('SHA1', @HashThis + @Salt))),3,20)

UPDATE RegisteredUsers
SET NopPassword = @NewPassword, PasswordSalt = @Salt

Its doing what I want but it look like the first password in the table row is being used for all the rows, do i need to loop this in some way?

Many thanks,

S

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-16 : 10:47:00
[code]
DECLARE @Salt NVARCHAR(MAX)

EXEC dbo.sp_GenerateRandomString 8, @salt OUTPUT

UPDATE RegisteredUsers
SET NopPassword =SUBSTRING(UPPER(master.dbo.fn_varbintohexstr(HASHBYTES('SHA1', Password + @Salt))),3,20),
, PasswordSalt = @Salt
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

stegothdump
Starting Member

9 Posts

Posted - 2012-01-16 : 11:05:12
Hey visakh16,

Thanks for the quick reply, that has sorted my password col but the salt looks like it is the same...is there a way to run sp_GenerateRandomString for each row?

Many thanks,

S
Go to Top of Page
   

- Advertisement -