请看看这条存储过程出了什么错,总是报错“Server: Msg 128, Level 15, State 1, Procedure PPeriodical_Article, Line 17
The name 'Index' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.”CREATE PROCEDURE PPeriodical_Article(
@Method int,
@ID int = 0,
@Index int = 0,
@BookID int = 0,
@ColumnID int = 0,
@Title nvarchar(50) = '',
@AuthorName nvarchar(32) = '',
@AuthorInfo nvarchar(32) = '',
@Content ntext = '',
@Date datetime =NULL
)
WITH ENCRYPTION AS
IF @Method=1
BEGIN
INSERT INTO Periodical_Article([Index],BookID,ColumnID,Title,AuthorName,AuthorInfo,Content,[Date]) VALUES([Index]=@Index,BookID=@BookID,ColumnID=@ColumnID,Title=@Title,AuthorName=@AuthorName,AuthorInfo=@AuthorInfo,Content=@Content,[Date]=@Date)----------就是说这行出错!
END
ELSE IF @Method=0
BEGIN
UPDATE Periodical_Article SET [Index]=@Index,ColumnID=@ColumnID,Title=@Title,AuthorName=@AuthorName,AuthorInfo=@AuthorInfo,Content=@Content,Date=@Date WHERE ID=@ID
END
ELSE IF @Method=-1
BEGIN
DELETE Periodical_Article WHERE ColumnID=@ID
DELETE Periodical_Column WHERE ID=@ID
END
ELSE IF @Method=2
BEGIN
SELECT * FROM Periodical_Article WHERE ID=@ID
END
ELSE IF @Method=3
BEGIN
SELECT ID,[Index],Title,AuthorName,AuthorInfo,Date FROM Periodical_Article WHERE ColumnID=@ColumnID
END
GO
The name 'Index' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.”CREATE PROCEDURE PPeriodical_Article(
@Method int,
@ID int = 0,
@Index int = 0,
@BookID int = 0,
@ColumnID int = 0,
@Title nvarchar(50) = '',
@AuthorName nvarchar(32) = '',
@AuthorInfo nvarchar(32) = '',
@Content ntext = '',
@Date datetime =NULL
)
WITH ENCRYPTION AS
IF @Method=1
BEGIN
INSERT INTO Periodical_Article([Index],BookID,ColumnID,Title,AuthorName,AuthorInfo,Content,[Date]) VALUES([Index]=@Index,BookID=@BookID,ColumnID=@ColumnID,Title=@Title,AuthorName=@AuthorName,AuthorInfo=@AuthorInfo,Content=@Content,[Date]=@Date)----------就是说这行出错!
END
ELSE IF @Method=0
BEGIN
UPDATE Periodical_Article SET [Index]=@Index,ColumnID=@ColumnID,Title=@Title,AuthorName=@AuthorName,AuthorInfo=@AuthorInfo,Content=@Content,Date=@Date WHERE ID=@ID
END
ELSE IF @Method=-1
BEGIN
DELETE Periodical_Article WHERE ColumnID=@ID
DELETE Periodical_Column WHERE ID=@ID
END
ELSE IF @Method=2
BEGIN
SELECT * FROM Periodical_Article WHERE ID=@ID
END
ELSE IF @Method=3
BEGIN
SELECT ID,[Index],Title,AuthorName,AuthorInfo,Date FROM Periodical_Article WHERE ColumnID=@ColumnID
END
GO
select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date
select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date)
select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date
insert into 表(a,b,c) values ('a','b','c')
insert into 表 select 'a','b','c'
前面有个存储过程是这么写的,没有报错!这是为何?
INSERT INTO Periodical_Column(BookID,Name) VALUES(@BookID,@Name)
INSERT INTO MyTable (PriKey, Description)
VALUES (123, 'A description of part 123.')用 SELECT 子查询为一行或多行指定数据值。
INSERT INTO MyTable (PriKey, Description)
SELECT ForeignKey, Description
FROM SomeView