SQL 在此上下文中不允许使用名称“X”。有效的表达式是常量、常量表达式和变量。不允许使用列名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3761221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The name "X" is not permitted in this context. Valid expressions are constants, constant expressions, and variables. Column names are not permitted
提问by User7354632781
Using SQL Server. I am getting an error from an SQL Insert statement:
使用 SQL Server。我从 SQL 插入语句中收到错误消息:
The name "InvalidAwps" is not permitted in this context. Valid
expressions are constants, constant expressions, and (in some contexts)
variables. Column names are not permitted.
This is the Insert SQL that produces that error:
这是产生该错误的插入 SQL:
Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values (InvalidAwps, \uafc.com\ReportLinks\InvalidAwps);
And here is the table definition:
这是表定义:
Create Table [PlanFinder].[ReportLinks]
(
[TypeOfReport] Char (11) Not Null,
[Links] Money Null,
Constraint pk_TypeOfReport Primary Key Clustered (TypeOfReport)
)
How do I fix this?
我该如何解决?
回答by gbn
You need string delimiters
您需要字符串分隔符
Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values ('InvalidAwps', '\uafc.com\ReportLinks\InvalidAwps')
However, then you'll get errors inserting the string \\uafc.com\ReportLinks\InvalidAwps
into a money
column...
但是,将字符串\\uafc.com\ReportLinks\InvalidAwps
插入money
列中时会出错...
or are \\\InvalidAwps
,\\\Missing
meant to be symbols of some kind?
或者是\\\InvalidAwps
,\\\Missing
意味着某种符号?
回答by JNK
Try putting InvalidAwps
in single quotes:
尝试放入InvalidAwps
单引号:
Insert Into [PlanFinder].[ReportLinks] (TypeOfReport, Links)
Values ('InvalidAwps', '\uafc.com\ReportLinks\InvalidAwps')
回答by Eric Leschinski
Reproduce this error in SQL Server.
在 SQL Server 中重现此错误。
Create a string column and use Double quotes to insert values instead of single quotes:
创建一个字符串列并使用双引号插入值而不是单引号:
create table yar (id VARCHAR(50));
insert into yar values("yarrrr");
Causes error:
导致错误:
Msg 128, Level 15, State 1, Line 1
The name "yarrrr" is not permitted in this context. Valid expressions are
constants, constant expressions, and (in some contexts) variables. Column names
are not permitted.
Fix it by using single quotes like this:
使用这样的单引号修复它:
create table yar (id VARCHAR(50));
insert into yar values('yarrrr');
Prints:
印刷:
(1 row(s) affected)