0

我收到此错误消息 102,级别 15,状态 1,过程 CostTest_02,第 43 行“;”附近的语法不正确。

用红色下划线的“GO”我一直在寻找错误,但我找不到!我对游标不是很有经验(这是我写的第一个)如果有人能发现它或任何其他错误,我将非常感谢

http://imgur.com/9k40O <----- 图片更清晰(推荐)

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE CostTest_02
AS
BEGIN

DECLARE @Issue_id int;
DECLARE @Master_id int;
DECLARE @Issue_table varchar(255);
DECLARE @price real;
DECLARE @rowcount bigint;


DECLARE cost_cursor cursor FOR
SELECT [Issue Id], [Master Id], [Issue Table], [Price]
from Adhoc_datafix..[Issue Table]
FOR UPDATE OF ADHOC_DATAFIX..[Issue Cost];

OPEN cost_cursor;
FETCH NEXT FROM cost_cursor into @Issue_ID, @Master_id, @Issue_table, @Price

WHILE @@FETCH_STATUS = 0
BEGIN

Select count(*) from @Issue_Table
set @Rowcount = @@rowcount

UPDATE ADHOC_DATAFIX..[Issue Cost]
set  [Issue Id] = @Issue_ID ,
[Master Issue Id] = @Master_ID ,
[Row Count] = (Select count(*) from @Issue_Table), --@Rowcount,
[Cost] = CAST(@Rowcount * @price as money)

WHERE CURRENT OF cost_cursor;
FETCH NEXT FROM cost_cursor
END

close cost_cursor;

DEALLOCATE cost_cursor;
GO
4

2 回答 2

1

我的猜测是FETCH NEXT FROM cost_cursor脚本底部附近的行应该是FETCH NEXT FROM cost_cursor into @Issue_ID, @Master_id, @Issue_table, @Price .

抱歉,再看这一行:

Select count(*) from @Issue_Table

没有意义,因为@Issue_table 实际上不是一个表,它是一个 nvarchar。
在运行时,它被转移到:

Select count(*) from 'Value of issue table field'

简而言之,这是行不通的。如果您想从表中动态获取计数,请查看这篇开创性文章

于 2013-01-10T13:29:21.160 回答
0

您没有END存储过程的语句。只需在前面添加GO

于 2013-01-10T13:31:22.307 回答