Field Name including a period gives me error (using brackets) - sql

I put together an Access Database for a department. They've been using it frequently for the past few months with no hiccups.
However, they changed one of the field names of a linked Excel File, which forces me to go into Access and update the query a bit.
The field name has gone from "PacU" to "Mr. Cooper"
Original:
SELECT Round(BidTemplate.[PacU],6) AS PacU
New:
SELECT Round(BidTemplate.[Mr. Cooper],6) AS [Mr. Cooper]
I am receing an error as follows "Invalid bracketing of the name 'BidTeample.[Mr.Cooper]'.
I'm sure the issue is driven off of the period that is now included in the field. But shouldn't the brackets take care of this?
What am I missing?

Field names cannot contain a period.
From the MS Access Documentation:
Names of fields, controls, and objects in Microsoft Access desktop databases:
Can be up to 64 characters long.
Can include any combination of letters, numbers, spaces, and special characters except a period (.), an exclamation point (!), an
accent grave (`), and brackets ([ ]).
Can't begin with leading spaces.
Can't include control characters (ASCII values 0 through 31).
Can't include a double quotation mark (") in table, view, or stored procedure names in a Microsoft Access project.

remove extra space
SELECT Round(BidTemplate.[Mr Cooper],6) AS [Mr Cooper]

Related

T-SQL CONTAINS and CONTAINSTABLE and punctuation like the period / dot

Is there a way to make full-text search in SQL Server 2012 a little more "naive", removing the "intelligence" that causes it to treat the [.] character as a word separator?
We have meaningful strings that contain dots and want to treat the entire string as a contiguous token, not as separate chunks.
Is there a place where such "punctuation" marks are defined, which can be easily edited to remove the "."?

set alias Name for Table visually

I want set a second name for my tables which is not in English letter. and when I want insert Table Name to a Table as a record, I use its alias name.
I know in each query we can use as to set second name, but I don't want do it by this way. I want set it as a property of a table.
Also please tell me how can I access to this property (alias name) in query?
I found this article, but I didn't found the alias field.
You can do that with a view:
CREATE VIEW EasyName
AS
SELECT * FROM LongComplicatedTableName
So long as the view only represents one table underneath, you can use all CRUD operations on the view.
According to MSDN, the naming restrictions for table names is as follows:
The first character must be one of the following:
A letter as defined by the Unicode Standard 2.0. The Unicode definition of letters includes Latin characters from a through z and
from A through Z, in addition to letter characters from other
languages.
The underscore (_), "at" sign (#), or number sign (#). Certain symbols at the beginning of an identifier have special meaning in SQL
Server. An identifier beginning with the "at" sign denotes a local
variable or parameter. An identifier beginning with a number sign
denotes a temporary table or procedure. An identifier beginning with
double number signs (##) denotes a global temporary object.
Some Transact-SQL functions have names that start with
double at signs (##). To avoid confusion with these functions, it is
recommended that you do not use names that start with ##.
Subsequent characters can be:
Letters as defined in the Unicode Standard 2.0.
Decimal numbers from either Basic Latin or other national scripts.
The "at" sign, dollar sign ($), number sign, or underscore.
The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words.
Embedded spaces or special characters are not allowed.
Supplementary characters are not allowed.
When used in Transact-SQL statements, identifiers that fail to comply
with these rules must be delimited by double quotation marks or
brackets.

Meaning of square brackets [] in MS-SQL table designer? [duplicate]

This question already has answers here:
What is the use of the square brackets [] in sql statements?
(10 answers)
Closed 7 years ago.
I have a copy of an existing database with existing records. when i was playing around with the table designer and noticed some of the column names have [] around them. they all seem to be arbitrary typed (float, datetime, netext, nvarchar etc) and there is nothing in column properties that gets rid of the []. I tried to rename delete the [] but it reappaears as soon as I exit edit.
according to this post, it is a keyword column for xml columns? but none of those columns are xml columns. Would someone kindly explain the purpose of this to a ms-sql newbie? thanks
The square brackets [] are used to delimit identifiers. This is necessary if the column name is a reserved keyword or contains special characters such as a space or hyphen.
Some users also like to use square brackets even when they are not necessary.
From MSDN:
Delimited identifiers
Are enclosed in double quotation marks (") or brackets ([ ]). Identifiers that comply with the rules for the format of identifiers may or may not be delimited.
SELECT *
FROM [TableX] --Delimiter is optional.
WHERE [KeyCol] = 124 --Delimiter is optional.
Identifiers that do not comply with all of the rules for identifiers must be delimited in a Transact-SQL statement.
SELECT *
FROM [My Table] --Identifier contains a space and uses a reserved keyword.
WHERE [order] = 10 --Identifier is a reserved keyword.
Square brackets may be placed around objects (e.g. views, databases, columns etc)
Their primary purpose is, as Mark mentioned, to encapsulate the objects so that special characters such as a space or period do not interfere with your syntax.
Many applications by default use the bracketed notation, to further reduce risk of syntax errors or anything of that sort.
It's typically good practice to not include any spaces
Database_Name < GOOD PRACTICE
Database Name < GENERALLY TRY TO AVOID
In any case, if the latter is used, you may use square brackets i.e.
select * from [Database Name]
the brackets are special characters in sql server that are used to explicitly delimit information.
they can be used in xml as per the article, they can also be used to specify meta names (column, table, etc.) that have spaces or other key words.
declare my column nvarchar(50)
would be invalid syntax, but you could do
declare [my column] nvarchar(50)
just think of them as explicit delimiters.

SQL Server query to create database is giving me an error when I include numeric characters in the database name

I am having trouble running a simple sql query in Microsoft SQL Server 2005 to create a database and im not sure why.
When I run this query
CREATE DATABASE 4444-virtual2
I receive this error
Incorrect syntax near '4444'.
Is there anything in particular that I must specify if I am creating a database table with numeric values in the name? Or am I forgetting something?
Database names need to start with a letter, underscore, at sign or number sign:
The first character must be one of the
following:
A letter as defined by the Unicode
Standard 3.2. The Unicode definition
of letters includes Latin characters
from a through z, from A through Z,
and also letter characters from other
languages.
The underscore (_), at sign (#), or
number sign (#).
Certain symbols at the beginning of an
identifier have special meaning in SQL
Server. A regular identifier that
starts with the at sign always denotes
a local variable or parameter and
cannot be used as the name of any
other type of object. An identifier
that starts with a number sign denotes
a temporary table or procedure. An
identifier that starts with double
number signs (##) denotes a global
temporary object. Although the number
sign or double number sign characters
can be used to begin the names of
other types of objects, we do not
recommend this practice.
Some Transact-SQL functions have names
that start with double at signs (##).
To avoid confusion with these
functions, you should not use names
that start with ##.
Unless you want to delimit every use of the name with double quotes "4444-virtual2" or brackets [4444-virtual2].
You can still create a database with that name, but you need to put it in quotes or brackets. e.g. this works:
CREATE DATABASE [4444-virtual2]
or this:
CREATE DATABASE "4444-virtual2"

Table/column names enclosed in square brackets, even though their names consist of legal characters

Square brackets allow you to use names for columns or aliases that contain characters not permitted for column names or aliases.
a) I’ve noticed that lots of times table and column names are enclosed inside square brackets, even though their names consist of perfectly legal characters. Why is that?
b) As far as I know, square brackets enclosing object’s name aren’t actually a part of that name. Thus, if we create a table named [A]:
CREATE TABLE [A] ( … )
we can later reference it without using brackets:
SELECT * FROM A
But why isn’t the same true when I try to reference a column KEY from a table returned by CONTAINSTABLE function? Namely, if I omit the brackets enclosing column name, I get an error:
SELECT ct.KEY
FROM CONTAINSTABLE(fullText,*,'some_string') as ct
thanx
KEY is a reserved word in SQL so requires the brackets to use it as a column name.
I think lots of the time you see superfluous square brackets may well be code generated by a tool. Management Studio puts them on when generating some scripts.
Brackets are not just for legal characters but to allow the use of otherwise reserved words for column names, etc.