How to Use SQL SELECT Statement Without Field Syntax ErrorLast reviewed: June 21, 1995Article ID: Q110752 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SYMPTOMSThe SQL command "SELECT FROM AuthorsTable" gives the following error message:
Syntax error in Select statement CAUSEThe SELECT statement must be followed immediately by a valid field name, or by an asterisk (*) to indicate all fields in the table. This requirement applies to all forms of the SELECT statement, including the SELECT INTO, SELECT ALL, SELECT DISTINCT, and SELECT DISTINCTROW statements.
RESOLUTIONIndicate the fields you want immediately after the SELECT statement, for example:
SELECT * FROM AuthorsTable STATUSThis behavior is by design.
MORE INFORMATION
SQL SELECT Statement SyntaxThe SQL SELECT statement specifies which fields you want to retrieve. You use the FROM clause to indicate which tables contain those fields. You use the WHERE clause to indicate which records are to be retrieved. SELECT is usually the first word in an SQL statement. If you include more than one field, separate the field names with commas. List the fields in the order you want them to be retrieved. If a field name appears in more than one table listed in the FROM clause, precede the field name with the table name and the . (dot) operator. In the following example, the AU_ID field is in both the Authors table and the Titles table. The SQL statement selects the Title field from the Titles table and the Author field from the Authors table:
SELECT Titles.Title.Dept, Author FROM Titles, Authors WHERE Titles.AU_ID = Authors.AU_IDVisual Basic requires the SQL command string (such as the one above) to be concatenated into one, single line in a string variable or quoted string. You can use an asterisk (*) to select all fields in a table. The following example selects all of the fields in the Publishers table:
SELECT Publishers.* FROM PublishersYou can use the AS reserved word to create an alias for a field name. The following example uses the Year for the field name:
SELECT [Year Published] AS Year FROM TitlesWhen you use a field name that contains a space or punctuation, surround the name with brackets:
SELECT [Year Published], Title FROM TitlesFor more information on SQL syntax, see the SQL topic in Visual Basic's Help menu.
Steps to Reproduce Behavior
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |