sql - How to escape square brackets inside square brackets for field name

ID : 274373

viewed : 27

Tags : sqlsql-serversql-server-2005tsqlescapingsql





Top 5 Answer for sql - How to escape square brackets inside square brackets for field name

vote vote

98

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.

vote vote

83

Hang a ] on the end of inline []

   SELECT [Eggs[scrambled]] or Bacon[fried]]] FROM Yummy 
vote vote

73

SET QUOTED_IDENTIFIER is ON by default so no need to escape anything

SELECT 1 AS "[Eggs[scrambled] or Bacon[fried]]" 
vote vote

63

In an SSIS SQL statement querying an excel sheet you must substitute square brackets for parenthesis to select individual columns. For example to select "My Column [Great Column]" you would SELECT [My Column (Great Column)] FROM [$A1:AX10000]

vote vote

51

Top 3 video Explaining sql - How to escape square brackets inside square brackets for field name







Related QUESTION?