2010-09-21 27 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) 
相關問題