How to escape square brackets inside square brackets for field name

后端 未结 4 1924
情书的邮戳
情书的邮戳 2020-12-06 16:40

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         


        
4条回答
  •  半阙折子戏
    2020-12-06 17:21

    You can use the quotename function to see the proper escaping.

    select quotename('Eggs[scrambled] or Bacon[fried]') 
    

    Returns

    [Eggs[scrambled]] or Bacon[fried]]]
    

    So all closing square brackets need to be doubled up.

提交回复
热议问题