• I have frequently had to script out Stored Procs that use dynamic SQL, and the joys of altering the number of quotes defies description.

    Using the 'Generate Scripts' option within SSMS is a useful solution for such situations and a lot of people don't realise that it can be used for such. It will create a script with the correct number of quotes, providing an easy way to script such things for moving to different databases.