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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Error using Text Driver in ASP

Status
Not open for further replies.

chris5g

Programmer
Joined
Aug 21, 2001
Messages
48
Location
US
Hi, this one is giving me a big headache.

I am reading from multiple CSV files that are exported from a program we use. Every once in a while I get this message and my program fails. Has anyone gotten this message before?

DB fields: title,Dauthor,collection,call,item#

Below is the error & description and the SQL statement.

Error: -2147217913 [Microsoft][ODBC Text Driver] The ORDER BY expression (Call) includes fields that are not selected by the query. Only those fields requested in the first query can be included in an ORDER BY expression.

SQL: SELECT * FROM 08apr2004.txt WHERE Collection <> 'sgov' AND Collection <> 'smac' Union SELECT * FROM 14apr2004.txt WHERE Collection <> 'sgov' AND Collection <> 'smac' ORDER BY Call ASC, Collection;

.my other programs are better.
 
I believe that CALL is a reserved word.

You really need to post this to the ASP or ODBC groups; this is the Microsoft SQL Server discussion group.

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
Firt you should NEVER use select * in a union statement. If one of the tables has an additional field addded to it, the code will break becasue each union won't have the same fields.

Since your error is intermittent, I would suggest that sometimes the csv imported doesn't have all the fields or names them differently.
 
I had to use the SELECT * because of the field name item#. I got an error if I tried to list them. I'm not sure how that is a legal field name but that is how it is in the database. Is there a way to write an SQL statement with field names that have special charaters?

As far as the same fields, I checked both csv files and they appear to be identical except for the data.

Thanks for the help =)

....my other programs are better
 
Enclose the name is brackets when using special characters or reserved words, [item#]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top