title: How can I write a SQL select statement to include a lookup from another table?
body: <p>I'm copying data from one database to another and massaging the data while I'm at it.  Both databases have tables called Clients and Jobs.  </p>
  
  <p>However, in database "Alpha" the Jobs table does not have a relationship to the Clients table, where database "Epsilon" does.  Alpha's Jobs table just has the Clients name in an nvarchar column.</p>
  
  <p>I need a select statement to lookup the Client's ID in the Client table by their name while I am inserting it into the Jobs table in Epsilon.</p>
  
  <p>My unfinished SQL statement looks like this:</p>
  
  <pre><code>insert into Epsilon.dbo.Jobs (ClientId, Name, Location, DateCreated)
      select ????, Name, Location, DateCreated from Alpha.dbo.Jobs
  </code></pre>
  
  <p>How can I modify this so that the ???? contains the ClientId from the Clients table in Epsilon?  I know I need to lookup the data using the Name column in Jobs, but I can't figure out the syntax for this.</p>