HOWTO: Use ADO to Query a Table with a Space in Its Name (189683)
The information in this article applies to:
- ActiveX Data Objects (ADO) 1.5
- ActiveX Data Objects (ADO) 2.0
- ActiveX Data Objects (ADO) 2.1 SP2
- ActiveX Data Objects (ADO) 2.5
- ActiveX Data Objects (ADO) 2.6
- ActiveX Data Objects (ADO) 2.7
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q189683 SUMMARY
ADO allows you to query a table based solely on its name. If just a table
name is specified, ADO prepends select * from and executes that query.
If the table you want to query is an Access table with a space in its name,
you need to place square brackets around the table's name.
MORE INFORMATION
If you want to query the Order Details table in the Access Northwind
(NWind.MDB) database that ships with many products using ADO, you need to
use code like the following:
rsOrderDetails.Open "[Order Details]", cnNWind, adOpenStatic, _
adLockReadOnly, adCmdTable
You can also use the back quote if you need to use the table name with
spaces. For example:
select * from `Order Details`.
NOTE: You can only use the back quote in Access. A standard quote will not work.
This information also applies when using the ADO Data Control that ships
with Visual Basic 6.0.
SQL Server 7.0 does support columns names with spaces.
table1 -------- table name
ff cc -------- column name
char(10)-------- column type
In ISQL ( aka query analyzer) you can use
select [ff cc] from table1
insert will occur via
insert into table1([ff cc]) VALUES('xx')
If you execute the statement
set quoted_identifier on
You can use
select 'ff cc' from table1
You can create a table that have column names with spaces
like:
create table table1([col1 xx] integer)
A standard quote will not work.
Back quotes do not currently work with back end as SQL Server 7.0.
Modification Type: | Minor | Last Reviewed: | 3/2/2005 |
---|
Keywords: | kbDatabase kbhowto kbJET KB189683 |
---|
|