You are here: Re: Querying a column with brackets in its name « MsSQL Server « IT news, forums, messages
Re: Querying a column with brackets in its name

Posted by Erland Sommarskog on 10/01/46 11:42

Stu (stuart.ainsworth@gmail.com) writes:
> Obviously, I don''t work with brackets in my table names; just curious,
> why the double "]" at the end? I just tried it, and it blew up. I'd
> like to know so that when I encounter it in the future, I'll understand
> what's going on.

Because in T-SQL whenever you need to include the closing delimiter in
whatever you are delimiting, you need double it:

PRINT 'It''s one o''clock, and time for lunch'
SELECT * FROM [My[]]brackets]
SELECT "Double""quote" = '"'

There is a built in function that can help you with this: quotename().

SELECT quotename('MTIC_PROD_VEND[ 1]')
SELECT quotename(@myinput, '''')



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация