title: How to update 2 tables without a join and without using a loop
body: <p>I have 2 tables, one contains people and one contains vouchers, i need to assign a voucher to each person and update the voucher table with the id of the person it was assigned to. Since there are no common keys to join the tables i can't use a recursive CTE, and i'd always try to avoid using a loop but i can't think fo any other way. </p>
  
  <p>Is there anyway to do without using a loop? ideally in a single statement.</p>
  
  <p>This will give an example of the tables (I am using SQL Server 2008 R2)</p>
  
  <pre><code>CREATE TABLE Persons (ID INT IDENTITY(1,1), 
                        FirstName VARCHAR(30), 
                        LastName  VARCHAR(50),      
                        Voucher CHAR(5))
  
  CREATE TABLE Vouchers (Voucher CHAR(5), 
                         Assigned INT)
  
  INSERT INTO Persons (FirstName,LastName) VALUES ('Rob','Smith')
  INSERT INTO Persons (FirstName,LastName) VALUES ('Alan','Brown')
  INSERT INTO Persons (FirstName,LastName) VALUES ('John','Plant')
  INSERT INTO Persons (FirstName,LastName) VALUES ('Mike','Black')
  INSERT INTO Persons (FirstName,LastName) VALUES ('Steve','Green')
  
  INSERT INTO Vouchers (Voucher) VALUES ('FEWPN')
  INSERT INTO Vouchers (Voucher) VALUES ('ROPIW')
  INSERT INTO Vouchers (Voucher) VALUES ('NGLCE')
  INSERT INTO Vouchers (Voucher) VALUES ('WEKFE')
  INSERT INTO Vouchers (Voucher) VALUES ('POIAP')
  </code></pre>