【问题标题】:Incorrect syntax in stored procedure存储过程中的语法不正确
【发布时间】:2013-12-23 00:39:38
【问题描述】:

我写了一个更新存储过程,这里是代码

CREATE PROCEDURE writer_update_art
    @articleid int
    @title nvarchar(50) ,
    @subject text ,
    @tag nvarchar(25),
AS
    update articles 
    set (title = @title, subject = @subject, tag = @tag) 
    where articleid = @articleid

    RETURN

但出现错误:

'@title'附近的语法不正确
'(' 附近的语法不正确

【问题讨论】:

  • ntexttextimage 数据类型将在 SQL Server 的未来版本中删除。避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。请改用nvarchar(max)varchar(max)varbinary(max)See details here

标签: sql sql-server linq


【解决方案1】:

SET 语法不需要括号,而且逗号放错了位置:

CREATE PROCEDURE writer_update_art
    @articleid int,
    @title nvarchar(50),
    @subject text,
    @tag nvarchar(25)
AS
    update articles set title = @title , subject=@subject , tag=@tag 
    where articleid=@articleid
RETURN

【讨论】:

  • 其实我放括号是为了解决这个问题!!但它没有用
  • 我后来也注意到了逗号。逗号是问题的根源
【解决方案2】:

参数列表末尾不需要内括号或额外的逗号(列表中第一个参数后需要逗号):

CREATE PROCEDURE writer_update_art
(
    @articleid int,
    @title nvarchar(50) ,
    @subject text ,
    @tag nvarchar(25)
)
AS
    update articles 
    set title = @title, 
        subject = @subject, 
        tag = @tag 
    where articleid = @articleid
RETURN

【讨论】:

  • @articleid int后面还少了一个逗号
  • 没用! ...和一个新的错误说:'必须声明缩放变量“@title”。 !
  • 哇谢谢!! @Mitch Wheat .. 成功了!!!!!!好奇怪我还是不知道问题出在哪里!
  • 你还不知道怎么回事??尽管他们有两种解释?
  • 是的......因为我总是做我写的事情,这个错误以前从未出现过!
猜你喜欢
  • 2019-05-29
  • 1970-01-01
  • 2020-06-23
  • 2011-06-12
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 2020-07-05
相关资源
最近更新 更多