<p>Two table:</p>

<pre><code>StoreInfo:
UserId uniqueidentifier
StoreNo nvarchar
UserName nvarchar
Password nvarchar

UserInfo:
UserId uniqueidentifier
UserName nvarchar
Password nvarchar
</code></pre>

<p>the UserId on StoreInfo is currently null. How do i update StoreInfo's UserId with UserInfo's UserId based on StoreInfo's UserName and Password is match to the UserName and Password from UserInfo. </p>

<p>the following is the query that i wrote which update the entire UserId in StoreInfo with the first UserId from UserInfo so i know it's wrong.</p>

<pre><code>declare @UserName nvarchar(255)
declare @Password nvarchar(25)
declare @UserId uniqueidentifier

select @UserName = UserName, @Password = Password, @UserId = UserId
from UserInfo

select UserId, Password 
   from FranchiseInfo 
   where UserID = @UserName and Password = @Password

update FranchiseInfo
set UserI = @UserId
</code></pre>

```
```
UPDATE StoreInfo
 set UserId = ui.UserId
 from StoreInfo si
  inner join UserInfo ui
   on ui.UserName = si.UserName
    and ui.Password = si.Password
 where si.UserId is null
```
```
This will update all rows in the table where UserId is not set.  Build out the where clause if you only want to update selected rows.  (I haven't tested this, so watch for typos!)