English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If my column name contains space, what kind of quotation can i use ?

for example, if my table is (product name, price), would this be correct ? i used double-quotes .. is it correct ?

SELECT "product name"
FROM MyTable
WHERE "product name" LIKE 'SQL book'

Please tell me what will exact syntax look like in this case ?

Thanks

2007-01-05 19:09:26 · 8 answers · asked by Zettag 2 in Computers & Internet Programming & Design

8 answers

The syntax depends on the system you're using. What you have above will work for Oracle, but in MS Access you'd use [ ] rather than the quotes.

Also note that since the column name is quoted, case will matter in some databases.

Avoid using spaces in your object names - it'll cause nothing but pains.

2007-01-05 19:16:11 · answer #1 · answered by BigRez 6 · 0 0

Yes, you can use double quotes, but also square brackets. You may be better off with them to distinguish table or field names with literals.

select [product name] from mytable where [product name] like 'sql book'

Oh: this is for SQL Server. Square brackets also for MS Access. Can't vouch for other sql dialects (oracle...).

2007-01-05 19:21:47 · answer #2 · answered by miket 4 · 0 0

if your connection string code is in the same code as the insert code, I'd segment out each statement a bit. what you are showing is PHP code with SQL statements assuming the code it breaking on line 1

2016-05-22 22:17:48 · answer #3 · answered by Anonymous · 0 0

till date i havent come across a database that accpets spaces between the column names.. during table creation phase.

u cant do something like :

CREATE TABLE mytable
(product name varchar(20 ) );

it will give u an error.

this is valid for DB's i have worked with Oracle,MsSQL
and Postgre

u have to do something like

CREATE TABLE mytable
(product_name varchar(20 ) );

2007-01-05 19:17:09 · answer #4 · answered by AJ 1 · 0 0

Oh and just to add... for the 'like' predicate you need to use a percent sign otherwise you will never find any records unless there is an exact match. e.g.

Where myField like 'Smith%'

will find anything that begins with the word 'Smith' and

where myField like '%Smith'

will find anything that ends with the word 'Smith' and

where myField like '%Smith%' will find anything where the word 'Smith' exists in the field data.

2007-01-05 20:52:55 · answer #5 · answered by jools 3 · 0 0

square brackets work with sql server and access, but it is best practise not to have spaces, and use and underscore between words

2007-01-05 19:35:06 · answer #6 · answered by Anonymous · 0 0

if a name contains space(s) you should use [ ] for accessing to it.
for example::

select * from myTable
where [st num]="name"

2007-01-06 06:00:26 · answer #7 · answered by Moein 3 · 0 0

<0098741>****>>>>>>S--___ - Quote > DLL. ?lamb>?..**%%%.regetit&&**)

2007-01-05 19:14:44 · answer #8 · answered by six 4 · 0 3

fedest.com, questions and answers