title: SQL REPLACE special characters with value from another table
body: <p>All,</p>
  
  <p>I am trying to replace the special characters in a string with the URL 
  encoding values to which they correspond. Below is some example code I have 
  been working with.</p>
  
  <p>Thanks for the help.</p>
  
  <pre><code>create table #url_encoding_lookup(character varchar(10), code varchar (20))
  
  insert into  #url_encoding_lookup (character, code)
  values 
  ('!',   '%21'),
  ('"',   '%22'),
  ('#',   '%23'),
  ('$',   '%24'),
  ('%',   '%25'),
  ('&amp;',   '%26'),
  ('''',  '%27'),
  ('(',   '%28'),
  (')',   '%29'),
  ('*',   '%2A'),
  ('+',   '%2B'),
  (',',   '%2C'),
  ('-',   '%2D'),
  ('.',   '%2E'),
  ('/',   '%2F')
  
  
  Create   table #data
  (string varchar (200))
  
  insert into #data
  values
  
  ('Jim (BoB)'),
  ('Will''s Place'),
  ('Auto-Mart')
  
  
  select * from #data
  select * from #url_encoding_lookup
  
  desired results would be 
  
  Jim %28Bob%29
  Will%27s Place
  Auto%2DMart
  </code></pre>