Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-07-09 : 17:36:21
|
| Hi All - I'm trying to add a column name which already includes square brackets in the column name. The actual column name is '[1] Question 1'.It's not letting me. Any ideas?[CODE]ALTER TABLE Table1ADD [[1] Question 1] NVARCHAR(MAX)GO[/CODE] |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-07-09 : 17:43:51
|
| Hi Tara - This is the way the table was previously coded. the table is linked to SSRS flows, and would take too much work to change the column names.Any idea on how I can add column as described above? Thanks! |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-09 : 18:00:16
|
Use double quotes to escape. ALTER TABLE Table1ADD "[1] Question 1" NVARCHAR(MAX)GO If you need to use double quotes in your column name, use square brackets as escape.Now, if you want to use both square brackets AND double quotes in your table name, what should one do? (Left as an exercise to the reader so s/he can torture himself/herself). |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-09 : 18:04:59
|
I think it was Rob Volk who had a SQL Saturday presentation on how to torture yourself (or others) using imaginative column names. I think the following gems are from that:CREATE TABLE #tmp("[id]x" INT);CREATE TABLE #tmp2 ("[idx]]" INT, ["abcd"] INT)CREATE TABLE #tmp3 (" " INT);CREATE TABLE #tmp4 ([[abcd[] INT);CREATE TABLE #tmp5 ([[[[] INT);CREATE TABLE #tmp6 ("[[""]]""" INT);(Rob, if it was not you, my apologies). |
 |
|
|
|
|
|