DelphiFAQ Home Search:

Simple SQL query fails with Invalid Column Name (MS-SQL)

 

comments8 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Question:

I want to delete all records in my MS-SQL database that contain the city "Alexandria".
The SQL looks like this:

delete from plants where city_name = "Alexandria"

I get this error message that something does not match with a table name or alias name used in the query or that I use an Invalid Column Name 'Alexandria'.

Answer:

Many SQL parsers will allow strings to be escaped either by ' or " (single or double quote).
If you write SQL for Microsoft SQL Server, you have to use single quotes instead of double-quotes.

// bad in Microsoft SQL
delete from plants where city_name = "Alexandria"

// correct
delete from plants where city_name = 'Alexandria'

Content-type: text/html

Comments:

2012-08-13, 10:24:06
[hidden] from United States  
rating
How can I disable this silly MSSQL behavior?
2014-12-17, 03:17:00
anonymous from Brazil  
Third Flower My spouse and i have aldraey been now delighted that Albert could carry out his reports on account of the concepts he had through your online page. It really is now and again perplexing to only constantly be freely giving techniques which some people c
2014-12-20, 09:43:12
anonymous  
we prefer to honor lots of other world-wide-web web sites on the<a href=' http://vtnmpkjnpio.com'> inerentt</a>, even though they aren?t linked to us, by linking to them. Below are some webpages worth checking out
2015-01-30, 00:45:41
anonymous from San Jose, United States  
Third Flower My spouse and i have alaredy been now delighted that Albert could carry out his reports on account of the concepts he had through your online page. It really is now and again perplexing to only constantly be freely giving techniques which some people c
2015-01-30, 01:13:45
anonymous from Singapore  
Remarkable story, believed we're able to blend a nmebur of unrelated data, nevertheless truly worth taking a look, wow did one know about Middle of the East has got a lot more problems just as well
2015-01-30, 01:13:45
anonymous from Singapore  
Remarkable story, believed we're able to blend a nmebur of unrelated data, nevertheless truly worth taking a look, wow did one know about Middle of the East has got a lot more problems just as well
2015-01-30, 01:13:45
anonymous from Singapore  
Remarkable story, believed we're able to blend a nmebur of unrelated data, nevertheless truly worth taking a look, wow did one know about Middle of the East has got a lot more problems just as well
2017-02-22, 15:17:44
Jame from Toronto, Canada  
rating
On this day, soon after church solutions, the persons of Ireland have been permitted to feast,
and was the only day in the 40 day Lent period that Irish Catholics were permitted
to eat meat and drink.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: