请看看这条存储过程出了什么错,总是报错“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

解决方案 »

  1.   

    INSERT INTO Periodical_Article([Index],BookID,ColumnID,Title,AuthorName,AuthorInfo,Content,[Date]) 
    select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date
      

  2.   

    --orINSERT INTO Periodical_Article([Index],BookID,ColumnID,Title,AuthorName,AuthorInfo,Content,[Date]) values( 
    select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date)
      

  3.   

    INSERT INTO Periodical_Article
    select @Index,@BookID,@ColumnID,@Title,@AuthorName,@AuthorInfo,@Content,@Date
     
     
      

  4.   

    请问高人们,insert into values 和insert into select 有什么区别?
      

  5.   

    语法 insert into 表(a,b,c)(valuea,valueb,valuec)
      

  6.   

    语法 ,你语法错误了
    insert into 表(a,b,c) values ('a','b','c')
    insert into 表 select 'a','b','c'
      

  7.   

    为什么有时用insert into t() values() 可以,有时必须要用insert into t() select ****
      

  8.   

    谢谢楼上热心
    前面有个存储过程是这么写的,没有报错!这是为何?
    INSERT INTO Periodical_Column(BookID,Name) VALUES(@BookID,@Name)
      

  9.   

    insert有两种方法指定数据值: 用 VALUES 子句为一行指定数据值: 
    INSERT INTO MyTable (PriKey, Description)
           VALUES (123, 'A description of part 123.')用 SELECT 子查询为一行或多行指定数据值。 
    INSERT INTO MyTable  (PriKey, Description)
           SELECT ForeignKey, Description
           FROM SomeView