INSERT INTO query, MS Access

AGx-07_162

Honorable
Sep 16, 2013
58
0
10,610
5
Can anyone help me understand why I get a "Syntax error in INSERT INTO statement" error with this query?

INSERT INTO Employees (Title, FirstName, LastName, Company, Department, Mailstop, Extension, City, State, Bldg, Floor, DirList, Prefix, Notes, Phone, importID, importDate, Desc)

SELECT Title, FirstName, LastName, Company, Department, Mailstop, Extension, City, State, Bldg, Floor, DirList, Prefix, Notes, Phone, importID, importDate, Desc

FROM dbo_Employees


Please take note of the column in blue, "Desc". This appears to be the problem column as if I remove it from the statement the query works fine. The confusing thing is that, with the exception of the importID column, every column in both tables are exactly the same. And I mean exactly the same. They are all Text columns with the exact same properties. I even looked specifically at the Desc column in both tables and made sure each of their properties were exactly the same. Same length, no default values, neither are required, indexed, both allow zero length. They are practically twins.

Any ideas why I'm getting this error?
 

ksham

Honorable
Mar 29, 2013
175
0
10,760
25
Desc is a SQL keyword. It's bad practice to name a table column "Desc" or any other reserved SQL keywords. But if you want to stick with it, use backticks - `Desc`
 

ksham

Honorable
Mar 29, 2013
175
0
10,760
25
Desc is a SQL keyword. It's bad practice to name a table column "Desc" or any other reserved SQL keywords. But if you want to stick with it, use backticks - `Desc`
 

AGx-07_162

Honorable
Sep 16, 2013
58
0
10,610
5
Thank you. I wasn't aware of that. I'm certainly no expert but unfortunately I'm stepping into an environment that existed before me. I should be able to get around it if I just do [Desc] instead.

Thanks again.
 

AGx-07_162

Honorable
Sep 16, 2013
58
0
10,610
5


I'll try to do that when I can. I was able to make it work by just putting [ ] around the column name.

INSERT INTO Employees (Title, FirstName, LastName, Company, Department, Mailstop, Extension, City, State, Bldg, Floor, DirList, Prefix, Notes, Phone, importID, importDate, [Desc])

SELECT Title, FirstName, LastName, Company, Department, Mailstop, Extension, City, State, Bldg, Floor, DirList, Prefix, Notes, Phone, importID, importDate, [Desc]

FROM dbo_Employees

 

ksham

Honorable
Mar 29, 2013
175
0
10,760
25
Agreed; it's not recommended. Also, based on that query, the DB design is optimal. Company and Department should be an association table with Department being its own table. Address should be its own thing too IMO.
 

USAFRet

Illustrious
Moderator
Also, based on that query, the DB design is optimal
I think you meant to say "sub-optimal".
There are many things I'd change about that.

Employee - FName, LName, Phone Num
Belongs to a Department - HP, IT, whatever
Is associated with a Location. Building, City, State, etc.
 

AGx-07_162

Honorable
Sep 16, 2013
58
0
10,610
5


There are a lot of things wrong with the database. The design doesn't bother me as much as the inconsistency in the data. Almost everything is a Text(255) field and users just jam whatever they want into whatever field they want.
 
Thread starter Similar threads Forum Replies Date
L Apps General Discussion 1
T Apps General Discussion 2
J Apps General Discussion 2
S Apps General Discussion 2
T Apps General Discussion 1
A Apps General Discussion 1
kol12 Apps General Discussion 10
C Apps General Discussion 2
M Apps General Discussion 1
P Apps General Discussion 5
H Apps General Discussion 1
M Apps General Discussion 1
A Apps General Discussion 3
K Apps General Discussion 3
viveknayyar007 Apps General Discussion 0
viveknayyar007 Apps General Discussion 0
C Apps General Discussion 1
A Apps General Discussion 1
B Apps General Discussion 2
M Apps General Discussion 1

ASK THE COMMUNITY