Microsoft KB Archive/189683

= HOWTO: Use ADO to Query a Table with a Space in Its Name =

Article ID: 189683

Article Last Modified on 3/2/2005

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



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.

Keywords: kbhowto kbdatabase kbjet KB189683

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.