Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Incorrect Syntax near 'INDEX'

Status
Not open for further replies.

NikeGuy23

MIS
Jun 17, 2002
108
CA
When using excel query to pull data from a Microsoft SQL server 2008 even the most basic query such as pull everything from one table, and one field = C we get the error of Incorrect syntax near 'INDEX'. If this is intended as a part of a table hunt, A WITH keyward and parenthesis are now required.

I don't know what to do since i am using the Excel Query to create the lookup and pull the data back to Excel.
 
Without seeing the code, it's hard to determine how to fix it. Can you post the code - you can 'clean up' columns by using col1, col2 if you can't post the actual data.

Otherwise, I'm guessing you have the word INDEX as part of the FROM statement. If so, SQL Server thinks it is a query hint and expects the index name.


-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
That's the thing there is no code, I am just using excel query to pick the fields. HOWEVER in the table I have there is a field called INDEX. Might that be the issue?
 
Index is a reserved word. You should never use a reserved word for the name of a table or column, or anything else for that matter. I mean... you can, but you shouldn't. When you use a reserved word for a column (or table) you need to put square brackets around the column name, like this:

[Index]

Since you don't have any code, I'm not sure if this suggestion will help. One thing you could try doing is to create a computed column in your SQL table. Computed columns are not "real" columns, but are actually a formula. For example, if you had a Height column and another Width column, you could create a computed column for Area, like this:

Alter Table TableName Add Area As Height * Weight

Similarly, you could create a computed column in your table that simply returns your column data, like this:

Alter Table YourTableName Add MyDescription As Description

Then, you could pull this column in to Excel and you will have the same data that was in the Index column.

Your best approach here would be to simply rename the column if you can. Otherwise try the column alias trick.


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top