I have some dynamic SQL that generates column names. A quick example might be something like this:
SELECT dbo.getSomething(123) [Eggs[scrambled] or Bacon[fri
You can use the quotename function to see the proper escaping.
quotename
select quotename('Eggs[scrambled] or Bacon[fried]')
Returns
[Eggs[scrambled]] or Bacon[fried]]]
So all closing square brackets need to be doubled up.