title: How do you set a binary value from a string variable comprised of a binary literal in SQL Server?
body: <p>I have a table with a column of binary literals converted to strings that I need to relate to a table containing the same value as binary(16)  </p>
  
  <p>Root table string Value '2F774578C33011E880D80050569C29CA' </p>
  
  <p>table value I need to join to 0x2F774578C33011E880D80050569C29CA </p>
  
  <p>is there a way to convert either the root table to Binary by simply adding the 0x to the string then declaring the string a literal value for the binary? or convert the binary to the string contained in the root. </p>
  
  <p>I tried the following with no luck:  </p>
  
  <pre><code>DECLARE @jobIDBinary Binary(16) 
  DECLARE @jobString Nvarchar(50) 
  
  SET @jobIDBinary = '0x'+
  (SELECT TOP (1) JobId
  
  FROM  [Record]) 
  </code></pre>
  
  <p>error: Implicit conversion from data type nvarchar to binary is not allowed. Use the CONVERT function to run this query.</p>
  
  <p>I also tried converting the other way: </p>
  
  <pre><code> DECLARE @convo varchar(max) 
   SET @convo = (SELECT TOP (1)
   [BinaryJobID]
   FROM [GAPClaims].[dbo].[Record2]
  
   WHERE binaryjobId IS NOT NULL ) 
  </code></pre>
  
  <p>Results = ,]óJ¾¶‡Á§\ê€</p>
  
  <p>Thanks ahead of time. </p>