SQL: Select a column name "Short Name"

G

Guest

I cannot select a column if it has a space.

------------------------------------------------------------------------------------------
For example, i have a table:

Short name Code Year_Produced
ABA 1001 2005
BBB 1544 2001
CCC 1002 2000
------------------------------------------------------------------------------------------


I cannot select "short name" because there's a space in between

While i can select "Year_Produced" , because there's underscore("_") in
between.


------------------------------------------------------------------------------------------


How can I write an SQL to select name with space in between. Using quote ?
How ?

please kindly show me an example !

thank you , expert !!
 
J

John Spencer

In Access SQL you use square brackets if the column name has a space, is a
reserved word, or uses characters other than the Underscore, Letters, and
numbers.

SELECT [Short Name], Code, Year_Produced, [22], [Time], [All-Source]
FROM SomeTable

Explanation of why brackets.
Short Name has a space
22 is all numbers
Time is a reserved word (current system time)
All-Source is hyphenated and would be seen as a math expression (subtract
column "Source" from column "All") and ALL is a reserved word also.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Guest

My advise, never put spaces in the names of anything in Access. If you feel
you need the space for readability, use an _ to separate words. You can
select the field by wrapping it in brackets.

SELECT [Short name], Code, Year_Produced
FROM yourTable

HTH
Dale
 
G

Guest

Perfect explaination, Straight to the answer . Thank you !


--
Allen Phailat Wongakanit


John Spencer said:
In Access SQL you use square brackets if the column name has a space, is a
reserved word, or uses characters other than the Underscore, Letters, and
numbers.

SELECT [Short Name], Code, Year_Produced, [22], [Time], [All-Source]
FROM SomeTable

Explanation of why brackets.
Short Name has a space
22 is all numbers
Time is a reserved word (current system time)
All-Source is hyphenated and would be seen as a math expression (subtract
column "Source" from column "All") and ALL is a reserved word also.
--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

ali said:
I cannot select a column if it has a space.

------------------------------------------------------------------------------------------
For example, i have a table:

Short name Code Year_Produced
ABA 1001 2005
BBB 1544 2001
CCC 1002 2000
------------------------------------------------------------------------------------------


I cannot select "short name" because there's a space in between

While i can select "Year_Produced" , because there's underscore("_") in
between.


------------------------------------------------------------------------------------------


How can I write an SQL to select name with space in between. Using quote ?
How ?

please kindly show me an example !

thank you , expert !!
 
T

Tagory Torres

Guys,

I tried to use this, but it's not work with character "?"! Is there a solution to this problem?

I can't change the column name.



EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
J

John Spencer

Can you be clearer? What is the field name (column name) that you can't
specify?

Normally if the field name contains characters other than letters, numbers,
and underscores, then you refer to the field as bracket Field Name bracket
and to fully refer the name you use bracket table name bracket dot bracket
field name bracket.

[Some Table #].[Some field?]

Or in some cases (only one table in a query)
[Some field?]



--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top