简体   繁体   中英

Invalid column name when selecting

I have a table called Jobs with the following column names: JobID , Name , and Value . The table is filled like just one entry: 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'". Why can't I select by the value of the Name column? Doing JobID=1 or Value=10 will give me the proper result.

Use single quotes instead of double quotes. Single quotes are the standard for SQL string and date constants:

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).

将双引号"更改为单引号' 。双引号用于包围对象名称,可能以与[]相同的方式使用,因此对象名称中可以包含空格和其他通常无效的对象名称字符。另一方面,用于字符串文字。

使用而不是 。它将起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM