title: EXEC and Set Quoted_Identifier
body: <p>I've got a Stored proc [A] that creates another stored proc [B]</p>
  
  <p>[A] Will never be run by end users and has no parameters or other untrusted data. Instead it is used by me simply to automate the create of the complex SP [B]. [A] Will always have the same result unless it's internals are changed. Therefore I consider this to be safe.</p>
  
  <p>[B] requires Quoted_Identifiers ON as it uses xml.</p>
  
  <p>If I copy and paste the generated SP it works fine but if I let [A] create it with EXEC then the SP fails when running.</p>
  
  <p>I've tried adding <code>SET QUOTED_IDENTIFIERS ON</code> inside [B] but it has no noticeable effect.</p>
  
  <p>The same issue also occurs if I use sp_ExecuteSQL
  I've also tried setting it on before calling [B] but that also seems to have no effect (but why would it in a context where it was always on)</p>
  
  <p>My guess is that EXEC and sp_ExecuteSQL always use the setting OFF and the SET command is processed by the parser rather than the SQL engine itself. So how can I make EXEC create the proc correctly?</p>