Q: Assigning a local variable from a table using a join statement I'm working with SQL, and I can't seem to figure this out for the life of me.  
I have a local variable in my stored procedure called @curType.  I have two tables, DTXR and DP.  DP contains the columns type and programID.  DTXR contains the columns programID and QEI.  The stored procedure is passed the QEI, and I need to get the type from the table DP and assign it to the local variable @curType.  
So, I currently have 
select @curType = [Type] From DP d 
       Join DTXR x on d.ProgramId = x.ProgramID
       where x.QEI = @p_QEI.  

@p_QEI is the variable passed into the stored procedure.  
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:
select @curType = [Type] from DP Where DP.ProgramId = 120

But the join statement seems to be setting @curType to null.    

A: Actually, this should work. I would check to make sure that the following even returns anything at all (and if it does, what is the first result back?):
   select [Type] From DP d 
   Join DTXR x on d.ProgramId = x.ProgramID
   where dtxr.QEI = @p_QEI

That should be the problem, as here is a fiddle proving that a join does nothing different

A: I'm not sure if your code should works because of WHERE clause. IMO line:
   where dtxr.QEI = @p_QEI

should looks like:
   where x.QEI = @p_QEI

My second hint, please check @p_QEI variable, does it contain the proper value?
