Skip to Content.
Sympa Menu

freetds - RE: [freetds] Msg 170 Incorrect Syntax - could this be caused by oddcharacters in the table name?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Lowden, James K" <LowdenJK AT bernstein.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: RE: [freetds] Msg 170 Incorrect Syntax - could this be caused by oddcharacters in the table name?
  • Date: Thu, 1 Apr 2004 10:04:16 -0500

> From: Andy Cranston [mailto:a.cranston AT selwaymoore.com]
> Sent: April 1, 2004 6:04 AM
>
> $ ./csq A4800A
> select "Description","Manufacturer Code","Item Category Code"
> from "TEST SML$Item" where ("No_" = 'A4800A')
> Msg 170, Level 15, State 1
> Server 'BUSSYS', Line 1
> Line 1: Incorrect syntax near 'TEST SML$Item'.
> ./csq: part identifier lookup gave incorrect number of columns
> $
>
> So my syntax is wrong? Ok - so this is a tsql transcript to the same
> server:
>
> $ tsql -S BUSSYS -U dbreadonly
> locale is "C"
> locale charset is "646"
> Password:
> Msg 5703, Level 0, State 1, Server BUSSYS, Line 0
> Changed language setting to us_english.
> 1> use Test
> 2> go
> 1> select "Description","Manufacturer Code","Item Category Code"
> 2> from "TEST SML$Item" where ("No_" = 'A4800A')
> 3> go
> Description Manufacturer Code Item Category Code
> PCI FWD SCSI2 Interface Card HP MISC
> 1> exit
> $
>
> This works perfectly.
>
> The only thing I can think of is that the table name:
>
> TEST SML$Item
>
> contains a space and a $ (dollar) character. Could this be the cause of the
> syntax error and, if so, why does running the same query via tsql work when
> submiting the query via my C program does not?

Have a look at "Delimited Identifiers" in Books Online. "SET
QUOTED_IDENTIFIER ON" affects how the double-quote symbol works. Off, it
works like a single-quote, as a string delimiter. On, it indicates an object
identifier (e.g. table name or column name).

Rules of the game are that ODBC connections default to ON, and db-lib to OFF.
tsql's behavior is, er, undefined in this regard, as would be a ct-lib
connection (e.g. sqsh). ON adheres to SQL-92; OFF reflects how db-lib has
consistently worked since Sybase delivered its first server 20 years ago.

If I were writing your query, it would look like this:

select Description, [Manufacturer Code], [Item Category Code]
from [TEST SML$Item] where ([No_] = 'A4800A')

That's not standard SQL (yours is), but it will work with Microsoft servers
irrespective of the QUOTED_IDENTIFIER setting.

--jkl

-----------------------------------------
The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the original
message. Please note that we do not accept account orders and/or instructions
by e-mail, and therefore will not be responsible for carrying out such orders
and/or instructions.
If you, as the intended recipient of this message, the purpose of which is to
inform and update our clients, prospects and consultants of developments
relating to our services and products, would not like to receive further
e-mail correspondence from the sender, please "reply" to the sender
indicating your wishes. In the U.S.: 1345 Avenue of the Americas, New York,
NY 10105.





  • RE: [freetds] Msg 170 Incorrect Syntax - could this be caused by oddcharacters in the table name?, Lowden, James K, 04/01/2004

Archive powered by MHonArc 2.6.24.

Top of Page