title: Escaping single quote in SQL Server
body: <p>I was trying to execute the below statement to escape single quotes (i.e. using two single quotes):</p>
  
  <pre><code>declare @year varchar(max)
  set @year = '111,11';
  exec ('SELECT * FROM SplitValues(' + @year + ','','')');
  </code></pre>
  
  <p>I even tried to use <code>char(39)</code> instead of quotes:</p>
  
  <pre><code>declare @year varchar(max)
  set @year = '111,11';
  exec ('SELECT * FROM SplitValues(' + @year + ',' + char(39) + ',' + char(39) + ')');
  </code></pre>
  
  <p>But it didn't help. These are the only two solutions that I found on this site. Any help?</p>
  
  <p>This is the simplified query to clear up all your questions:</p>
  
  <pre><code>declare @year varchar(max)
  set @year = '111,11';
  SELECT * FROM SplitValues(@year , ',')
  </code></pre>
  
  <p>I want to achieve this, but using a dynamic query.</p>