title: Assigning a local variable from a table using a join statement
body: <p>I'm working with SQL, and I can't seem to figure this out for the life of me.  </p>
  
  <p>I have a local variable in my stored procedure called <code>@curType</code>.  I have two tables, DTXR and DP.  DP contains the columns <code>type</code> and <code>programID</code>.  DTXR contains the columns <code>programID</code> and <code>QEI</code>.  The stored procedure is passed the <code>QEI</code>, and I need to get the <code>type</code> from the table DP and assign it to the local variable <code>@curType</code>.  </p>
  
  <p>So, I currently have </p>
  
  <pre><code>select @curType = [Type] From DP d 
         Join DTXR x on d.ProgramId = x.ProgramID
         where x.QEI = @p_QEI.  
  </code></pre>
  
  <p>@p_QEI is the variable passed into the stored procedure.  </p>
  
  <p>The problem I'm running in to is this doesn't seem to set @curType.  It works if I manually set the program id like this:</p>
  
  <pre><code>select @curType = [Type] from DP Where DP.ProgramId = 120
  </code></pre>
  
  <p>But the join statement seems to be setting @curType to null.    </p>