For ODBC situations, this is often called "quoted identifier", i.e.
table or column containing special character or space. Different ODBC
drivers may support different enquoting characters. The double-quote
mark is SQL standard and used by SQL Server and Oracle. Sort of like you
used the square brackets.
Please check your database doc for "quoted identifier" to be sure. Also
in ODBC SDK specification for a good discussion. Doing little reading
will save you time on this topic.
Caution: If you have quoted identifier for table name, be careful to
only use single-quote mark around literal values! For example:
select * from "My Table" where name = 'foo'
Even as a quoted identifier, some special characters in table name may
still be illegal, depending on the specific ODBC driver. This may be
the problem where you have table name containing "#" character.
Bill
George Varga wrote:
>
> Hi everyone,
> I'm using the Perl DBI module (DBI:ODBC) to connect to a Microsoft Access
> database, and am using SELECT FROM WHERE and LIKE commands to retrieve
> data. The table name that I need to get data from contains spaces, and some
> of the field names contain spaces and "#".
> Examples:
> The table name is "This Is My Table" (without the double quotes).
> A field name is "Document #" (without the double quotes).
>
> I get an error when using these names in the Perl script:
> Cannot execute: [Microsoft][ODBC Microsoft Access Driver] Too few
> parameters. Expected 1. (SQL-07001)(DBD: st_execute/SQLExecute err=-1) at
> c:\art\website\home\cgi-bin\departments\htmltest.pl line 36.
> This message refers to the $sth = $dbh->prepare statement which contains
> the field name with the space and "#"
>
> This is an existing database that I would rather not touch or modify. Is
> there any special syntax or commands that would allow me to use these
> names? I used [] to enclose a field name that just had a space:
> [Document Title]
> That worked fine, but I tried to do the same with this one: [DOC #] and
> this did not work at all.
> The [] solution did not work for the table name either.