How to select a column name with a space in MySQL
Generally the first step is to not do that in the first place, but if this is already done, then you need to resort to properly quoting your column names:
SELECT `Business Name` FROM annoying_table
Usually these sorts of things are created by people who have used something like Microsoft Access and always use a GUI to do their thing.
how to SELECT a column which has a space in between its name
Single quotes ('
) denote character literals. I.e., you're selecting the string 'REJECTED COST'
, which, obviously, cannot be cast to a number.
In order to select a column name with a space, you should use double quotes ("
). Note that they need to be escaped, as you're using them inside a c++ string, which is also denoted by double quotes:
string sqlStmt = "SELECT \"REJECTED COST\", APPROVED_COST FROM COST_TABLE where PART_NUM= 'PN4879-1'";
How do you deal with blank spaces in column names in SQL Server?
select [Response Status Code], [Client Response Status Code]
from TC_Sessions (NOLOCK)
WHERE StartDate BETWEEN '05-15-2012' AND '06-01-2012'
AND SupplyID = 3367
Wrap the names in square brackets.
It is , however, best to avoid spaces in names if possible. It just creates more work for you down the road...
Handling column names with spaces in SQL Server
Looks like an error in your syntax, try this as an example:
UPDATE dbo.Survey
SET PhotoPathQ1 = null
WHERE [Q1 Photo Taken] = 0
This assumes that the field PhotoPathQ1
is nullable
and you actually want to insert a true null
value in to it rather than a string '(null)'
.
It also assumes that [Q1 Photo Taken]
is a bit
or int
field, although SQL Server will handle the conversion happily if you have it in quotes. If it's a string data type, then you should leave the quotes there.
You should use square brackets on field names that contain spaces instead of double quotes:
[Q1 Photo Taken]
Related Topics
Joining Tables from Different Servers
How Select Max(Salary) of Employee Each Department With Employee_Id and Emp_Name
Get Last Record of a Table in Postgres
Check If a Time Is Between Two Times (Time Datatype)
Sql Server - Join Rows into Comma Separated List
What Is and How to Remove Tablespace Error from My Database
Find a Matching Value in Date Range and Return Value
Hive Select Data into an Array of Structs
Sql - How to Sum/Aggregate Certain Rows in a Table
Selecting the First Day of the Month in Hive
Regex Pattern Inside SQL Replace Function
Update Table Column With Different Random Numbers
How to Return Pivot Table Output in MySQL
Retrieving the Last Record in Each Group - MySQL
Fetch the Rows Which Have the Max Value for a Column for Each Distinct Value of Another Column