title: Dynamic t-sql quotes in string
body: <p>I have the following in a stored procedure:</p>
  
  <pre><code>DECLARE @new_column_name varchar(9)
  DECLARE @table_name varchar(16)
  DECLARE @SQLString nvarchar(2000)
  
  SET @new_column_name = N'name'
  SET @table_name = N'tbl_test_table'
  
  SET @SQLString = N'SELECT @CountOUT = COUNT(*) FROM [' + @table_name + '] WHERE [' + @new_column_name + '] = ''' + @description + ''''``
  </code></pre>
  
  <p>This works absolutely fine until @description has a single quote in it. In my C# I replace single quotes with two single quotes but this is still causing a problem when creating the above SQL string.</p>
  
  <p>Any ideas how to fix this for:</p>
  
  <pre><code>SET @description = N'Adam''s Car'
  </code></pre>
  
  <p>The reason I am using dynamic SQL is because the 'name' column is temporary and only exists during the lifetime of the stored procedure.</p>