[ ] (Wildcard - Character(s) to Match) ?

B

Bruce Lawson

Hi, I am confused about Microsofts description of this Transact SQL
reference; [] (Wildcard - Character(s) to Match. The description says
"Matches any single character within the specified range or set that is
specified inside the square brackets". For example, in the TransactSQL
statement "UPDATE tblUsers SET [Password] = stringUserPassword WHERE UserId
= 2" , what do the brackets signify about the database record in column
Password being updated? TYIA
BruceL
 
K

Karl Seguin [MVP]

The [] have two meanings. The one you described is only applicable inside a
string with the LIKE operator...ala:

select blah from blahTable where description like '[ab]oat'

which doesn't really make sense, but you get the idea..

outside of this case, [] is used to escape reserved keyword names. Password
is actually a reserved word in TSQL, so the only way you can safely use it
as a column/table/sproc name it to wrap it in []. You can often omit the []
for reserved words, and TSQL will figure out what you mean, but I'd advise
against it.

If you type a query and a column name/table turns blue (or whatever color
your SQL syntax turns, like the word SELECT or FROM) than you should put it
in [] :)

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top