2010-09-21 97 views
2

使用SQL Server。我从一个SQL INSERT语句得到一个错误:在此上下文中不允许使用名称“X”。有效的表达式是常量,常量表达式和变量。列名不允许使用

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. 

这是插入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) 
) 

如何我解决这个问题吗?

回答

6

你需要字符串分隔符

Insert Into [PlanFinder].[ReportLinks] 
(TypeOfReport, Links) Values ('InvalidAwps', '\\uafc.com\ReportLinks\InvalidAwps') 

但是,那么你会得到错误。在插入串\\uafc.com\ReportLinks\InvalidAwpsmoney列...

或者是\\\InvalidAwps,\\\Missing意思是某种符号?

+0

我正要问这个。这是一个链接到一个文件或什么的? – JNK 2010-09-21 14:29:46

+0

@JNK:有些信息可能已被删除,因为它不是“代码布局”! – gbn 2010-09-21 14:32:01

+0

那实际上是报告的路径。谢谢我忘记了引号。 – User7354632781 2010-09-21 14:33:02

2

尝试把InvalidAwps在单引号:

Insert Into [PlanFinder].[ReportLinks] (TypeOfReport, Links) 
Values ('InvalidAwps', '\uafc.com\ReportLinks\InvalidAwps') 
0

在SQL Server中重现此错误。

创建一个字符串列,并使用双引号来插入值,而不是单引号:它使用单引号这样

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"); 

导致错误

create table yar (id VARCHAR(50)); 
insert into yar values('yarrrr'); 

打印:

(1 row(s) affected)