469,646 Members | 1,395 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

select statements

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.
Nov 16 '05 #1
5 2678
string Select = "Select [Table of Contents], Data Owner, Delegates From
NYC";

"freddy" <fr****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
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.

Nov 16 '05 #2
do not work

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

"freddy" <fr****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
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.


Nov 16 '05 #3

"freddy" <fr****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 16 '05 #4
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!!!

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Nov 16 '05 #5
In SQL Server, you need to you [] just as Jared said. Maybe you use a
different DB - what is ur DB?

"freddy" wrote:
do not work

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

"freddy" <fr****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
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.


Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Hans Maurer | last post: by
1 post views Thread by alexqa2003 | last post: by
3 posts views Thread by Tcs | last post: by
2 posts views Thread by =?Utf-8?B?VGVycnk=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.