title: Output sql query to a variable then create a new query
body: <p>I'm trying to output the query results from one table and using that same variable as a 'like' in another table. 
  The first part of the query is supposed to get me everything *. The variable (or array) will be used in the second part of the query as part of 'like'.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>DECLARE @UpnPref nvarchar(100), @WC nvarchar(10)
  Set @UpnPref = 0
  Set @WC = '*'
  
  Select @upnpref = UpnPrefix from dbo.ADUsers where UPNPrefix = @WC
  
  print @upnpref  &lt;-- returns a 0
  
  Select * from dbo.UserMailbox where LinkedAccount like '%' + @UpnPref +'%'
  </code></pre>