使用SQL Server。我从SQL Insert语句中收到错误:
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.
这是产生该错误的Insert SQL:
Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values (InvalidAwps, \\uafc.com\ReportLinks\InvalidAwps);
以下是表格定义:
Create Table [PlanFinder].[ReportLinks]
(
[TypeOfReport] Char (11) Not Null,
[Links] Money Null,
Constraint pk_TypeOfReport Primary Key Clustered (TypeOfReport)
)
我该如何解决这个问题?
答案 0 :(得分:8)
您需要字符串分隔符
Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values ('InvalidAwps', '\\uafc.com\ReportLinks\InvalidAwps')
但是,如果将字符串\\uafc.com\ReportLinks\InvalidAwps
插入money
列,则会出错...
或是\\\InvalidAwps
,\\\Missing
是什么意思?
答案 1 :(得分:2)
尝试将InvalidAwps
放在单引号中:
Insert Into [PlanFinder].[ReportLinks] (TypeOfReport, Links)
Values ('InvalidAwps', '\uafc.com\ReportLinks\InvalidAwps')
答案 2 :(得分:1)
在SQL Server中重现此错误。
创建一个字符串列并使用双引号来插入值而不是单引号:
create table yar (id VARCHAR(50));
insert into yar values("yarrrr");
导致错误:
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.
使用如下单引号修复它:
create table yar (id VARCHAR(50));
insert into yar values('yarrrr');
打印:
(1 row(s) affected)