double the single quote to escape a single quote.
SET @DynamicSQL =
'SELECT TOP 1 sys.tables.name, COUNT(*) AS TotalTable
FROM sys.tables
WHERE sys.tables.name NOT IN (''dtproperties'', ''sysdiagrams'')
GROUP BY sys.tables.name
ORDER BY sys.tables.name';