title: dynamic SQL help needed
body: <p>I have a dynamic SQL  statement that generates a series of update statement but it does not enclose the  value in the set clause and where clause in single quotation mark. does anyone know how to do fix this? here is my code.</p>
  
  <pre><code>  Declare @OldSSN VARCHAR(9)
    Declare @NewSSN VARCHAR(9)
    Declare @cmd   VARCHAR(MAX)
    Set @OldSSN='000000000'
    Set @NewSSN='000000001'
  
  Select @cmd =  COALESCE(@cmd,'') +
  '
     UPDATE ' + TABLE_NAME + ' SET ' + Column_Name + ' = ' + @NewSSN + '  
     WHERE ' + Column_Name + ' = ' + @OldSSN +'
  '
  
    From INFORMATION_SCHEMA.COLUMNS
   Where Column_Name like 'SSN%'       
   OR Column_Name LIKE 'ssn%'          
   OR Column_Name LIKE 'ssn%'          
   OR Column_Name LIKE '%_ssn%'            
   OR Column_Name LIKE '_ocsecno'          
   OR Column_Name LIKE 'Ssn%';
  
   Select @cmd
  </code></pre>
  
  <p>Output when executed</p>
  
  <pre><code>    UPDATE appl_view 
      SET    ssn = 000000001 
      WHERE  ssn = 000000000
  
    UPDATE ap_paid 
    SET    ssn = 000000001 
    WHERE  ssn = 000000000 
  </code></pre>
  
  <p>I'm trying to figure out how to enclose the ssn values in singe quotation mark as show below</p>
  
  <pre><code>    UPDATE appl_view 
      SET    ssn = '000000001' 
      WHERE  ssn = '000000000' 
  
    UPDATE ap_paid 
    SET    ssn = '000000001' 
    WHERE  ssn = '000000000'
  </code></pre>