select statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a select statement like this:
string Select = "Select TableofContents, DataOwner, Delegates From NYC";

and it work fine, but if I was to put a space in like this:
string Select = "Select Table of Contents, Data Owner, Delegates From NYC";

I would get an error in my da.fill(ds);

Why can I not use a space in my select statement. I have to connect to a db,
but I can not change it.
 
do not work

Jared said:
string Select = "Select [Table of Contents], Data Owner, Delegates From
NYC";

freddy said:
I have a select statement like this:
string Select = "Select TableofContents, DataOwner, Delegates From NYC";

and it work fine, but if I was to put a space in like this:
string Select = "Select Table of Contents, Data Owner, Delegates From
NYC";

I would get an error in my da.fill(ds);

Why can I not use a space in my select statement. I have to connect to a
db,
but I can not change it.
 
freddy said:
I have a select statement like this:
string Select = "Select TableofContents, DataOwner, Delegates From NYC";

and it work fine, but if I was to put a space in like this:
string Select = "Select Table of Contents, Data Owner, Delegates From NYC";

I would get an error in my da.fill(ds);

Why can I not use a space in my select statement. I have to connect to a db,
but I can not change it.

The short answer is that the names in your query must match the table and
field names defined in the database.
You cannot decide to introduce spaces in the names when you write the query.
What database are you using?
I believe the question is whether or not the database you are querying
allows spaces in table and field names.
The solution of enclosing the name in [] if there are spaces works OK in an
Access database, but many databases will not permit spaces in names.
Jared's response indicating use of [] should work in an Access database if
you have filed defined in the NYC table with names "Table of Contents" "Data
Owner" and "Delegates".
Freddy's response to Jared that his solution did not work is probably based
on the fact that Jared placed [] around only one of the two field names that
contain embedded spaces.
OTOH, Oracle would not have permitted field names with embedded spaces in
the first place.
IMHO, using table and field names with embedded spaces (even if permitted by
the DBMS) is a poor practice that will end up causing far more trouble than
it saves.
 
OTOH, Oracle would not have permitted field names
with embedded spaces in the first place.

YES it does - you must wrap the column or table name with double quotes.

Consider something like this:

CREATE TABLE "my stuff"{
"first name" VarChar2(30),
"last name" VarChar2(30))
TABLESPACE USERS
STORAGE(INITIAL 1M NEXT 1M PCTINCREASE 0)
/

SELECT "first name" FROM "my stuff"

and

SELECT *
FROM USER_TAB_COLS
WHERE TABLE_NAME='my stuff'
IMHO, using table and field names with embedded spaces (even if permitted by
the DBMS) is a poor practice that will end up causing far more trouble than
it saves.

I agree 100 percent!!!
 
In SQL Server, you need to you [] just as Jared said. Maybe you use a
different DB - what is ur DB?

freddy said:
do not work

Jared said:
string Select = "Select [Table of Contents], Data Owner, Delegates From
NYC";

freddy said:
I have a select statement like this:
string Select = "Select TableofContents, DataOwner, Delegates From NYC";

and it work fine, but if I was to put a space in like this:
string Select = "Select Table of Contents, Data Owner, Delegates From
NYC";

I would get an error in my da.fill(ds);

Why can I not use a space in my select statement. I have to connect to a
db,
but I can not change it.
 
Back
Top