[英]Invalid column name when selecting
I have a table called Jobs
with the following column names: JobID
, Name
, and Value
. 我有一个名为
Jobs
的表,具有以下列名: JobID
, Name
和Value
。 The table is filled like just one entry: JobID
: 1, Name
: TestJob, Value
: 10 该表充满像刚才一个条目:
JobID
:1, Name
:TestJob, Value
:10
I want to do select * from Jobs where Name="TestJob"
, but this gives me an error saying "Invalid column name 'TestJob'". 我想
select * from Jobs where Name="TestJob"
,但这给我一个错误,提示“无效的列名'TestJob'”。 Why can't I select by the value of the Name
column? 为什么不能通过“
Name
列的值进行选择? Doing JobID=1
or Value=10
will give me the proper result. 做
JobID=1
或Value=10
会给我正确的结果。
Use single quotes instead of double quotes. 使用单引号而不是双引号。 Single quotes are the standard for SQL string and date constants:
单引号是SQL字符串和日期常量的标准:
select *
from Job
where Name = 'TestJob';
Some databases do accept double quotes for this purpose. 为此,某些数据库确实接受双引号。 It is always safest to use single quotes for string and date constants and double quotes to escape identifier names (if needed).
对字符串和日期常量使用单引号,对标识符名称进行转义(如果需要),总是最安全的。
将双引号"
更改为单引号'
。双引号用于包围对象名称,可能以与[]
相同的方式使用,因此对象名称中可以包含空格和其他通常无效的对象名称字符。另一方面,用于字符串文字。
使用“而不是” 。它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.