473,769 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct syntax for table variable names containing a space

Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"

Regards
Dynamo

Jul 17 '05 #1
5 2402
On 22 Nov 2004 07:50:30 -0800, Dynamo <Dy***********@ newsguy.com>
wrote:
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"


I'd suggest simply correcting the problem by NOT putting spaces in
such things as field names.

--
gburnore@databa six dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
=============== =============== =============== =============== ===============
Want one? GET one! http://signup.databasix.com
=============== =============== =============== =============== ===============
Jul 17 '05 #2

(1) Don't do that.
(2) If you must, use backticks (`) around the offending column name:

$query = "INSERT INTO Catalogue (`Book title`) VALUES ('The Crow')";
---
Steve

Jul 17 '05 #3
.oO(Dynamo)
What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.


http://dev.mysql.com/doc/mysql/en/Legal_names.html

Micha
Jul 17 '05 #4
On 22 Nov 2004 07:50:30 -0800, Dynamo <Dy***********@ newsguy.com> wrote:
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"


RENAME would be a good idea... spaces in a table name is a particularly bad
idea.

If you insist on keeping it, then double quotes are the standard method, to
produce a "quoted identifier".

$query = "INSERT INTO Catalogue (\"Book title\") VALUES ('The Crow')"

Specific databases may have alternatives, or not accept the standard
identifier quoting method, however you didn't state what database you're using.

(But anyway... rename the table... really).

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #5
Try putting the name in square brackets.
"Dynamo" <Dy***********@ newsguy.com> wrote in message
news:cn******** *@drn.newsguy.c om...
Hello again ;-)

What is the correct syntax to use when inserting a value into a table that
contains a variable name with spaces.

This works

$query = "INSERT INTO Catalogue (Author) VALUES ('Stephen King')"

And this does not

$query = "INSERT INTO Catalogue (Book title) VALUES ('The Crow')"

Regards
Dynamo

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2897
by: Margaret MacDonald | last post by:
It appears that the 'table.field' dot notation is not preserved by php's mysql library. I can create some join 'SELECT a.id, b.id FROM table1 AS a, table2 AS b' but when I try to refer to the fields as 'a.id' and 'b.id' the reference fails because the table aliases have been discarded from the dataset as managed by php. 'a.id' has become merely 'id', and 'b.id' no longer has a fieldname -- the only way to refer to it is by the numeric...
699
34158
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
4
3719
by: David | last post by:
Hi, I have taken some SQL taken from a query in Access 2000, but I cannot seem to get it working correctly in my .asp page. strQuery = strquery & "FROM Schedule_Selector INNER JOIN ((Orders INNER JOIN (StockMovements INNER JOIN OrderLines ON StockMovements.JobNumber = OrderLines.JobNumber) ON Orders.OrderID = OrderLines.OrderID) INNER JOIN Products ON OrderLines.ProductID =
4
2856
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard code data for the other variable. So, I think I have a syntax problem when trying to use "FrontPage.@FrontpageProduct" as seen in my example code below. I've tried many variations... and either get syntax errors or end up with a result of "no...
8
2092
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is, I've been playing with Qt in KDE on a Slackware 10.0 system, and following their cookbook exercises, and everything's working, and I have no clue what the code is doing, i.e.. how do I connect my brain to the ascii in the files to the stuff on...
166
8666
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
177
7069
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
6
4849
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
28
8199
by: Sriram Rajagopalan | last post by:
Hi, I was interested to know if there is a way to use a variable name split across multiple lines in C. For example : int this_is_a_very_long_variable_name = 10; I would like to split the "this_is_a_very_long_variable_name " into 2
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.