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)
 Update a column with random number

Author  Topic 

matrixrep
Starting Member

30 Posts

Posted - 2012-11-07 : 13:55:55
I have a stored procedure that generate a password the way i want.

I want to update the field password in a table containing 3 columns (userID, name, password)

What is the best way to put a different password for each userid ?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-07 : 14:09:21
Easier if you can make the query in-line, or convert it into a function rather than a stored proc. If you were to convert it to a function, then you can do something like shown below:
UPDATE y SET
y.Password = f.Password
FROM
YourTable y
CROSS APPLY dbo.YourFunction(userId,[name]) f
Go to Top of Page

matrixrep
Starting Member

30 Posts

Posted - 2012-11-07 : 14:33:15
I need to use my stored procedure.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-07 : 15:31:39
Could you make your stored procedure a function? A function is more appropriate for this task.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

matrixrep
Starting Member

30 Posts

Posted - 2012-11-08 : 09:10:04
I cannot use a function. My stored procedure generate only a random password.
Go to Top of Page

matrixrep
Starting Member

30 Posts

Posted - 2012-11-08 : 09:37:35
Thanks for your help


Declare @Password nvarchar
UPDATE MyTABLE
SET Password = dbo.Myfunction(@Password)
WHERE ...

That did the trick for me.
Go to Top of Page
   

- Advertisement -