You can always use a cursor, even though they are frowned upon because of performance reasons. But if your not going to run this often it shouldn't matter.
DECLARE tablecursor CURSOR FOR
SELECT pkid FROM mytable
OPEN tablecursor
FETCH NEXT FROM tablecursor INTO @pkid
WHILE @@FETCH_STATUS = 0
BEGIN
set @randPass = 'abc123'
update mytable set password = @randPass where pkid = @pkID
FETCH NEXT FROM tablecursor
INTO @pkid
END
CLOSE tablecursor
DEALLOCATE tablecursor
GO
>Thanks for the reply.
>
>I wasn't clear enough, though. I have an existing table with a password field. I want to populate that field in every row with a different password.
>
>John
>
>
>>You'll have to create temp table with structure that matches SP's result set first. For example, assuming that 'GenRand' SP returns integer,
CREATE TABLE #temp1 ( RandPass int )
>>INSERT INTO #temp1
>> EXECUTE ('GenRand')
>>SELECT RandPass
>> FROM #temp1
>>DROP TABLE #temp1
>>
>>>I would like to populate a password field in a table with a randomly generated password. I have a sp that generates the password, but cannot figure out how to use it in an INSERT statement. I tried to create a UDF but cannot use RAND() in it.
>>>
>>>TIA
>>>
>>>John