写了一个存储过程,总提示“必须声明标量变量”,怎么改?
存储过程如下:setANSI_NULLSONsetQUOTED_IDENTIFIERONgo--ALTERprocedure[dbo].[cbmtest]CREATEPR...
存储过程如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
--ALTER procedure [dbo].[cbmtest]
CREATE PROCEDURE cbmtest
as
begin
SET NOCOUNT ON;
@count int,
@unitID varchar(20),
@projectCodeTag varchar(4),
@threeYearsAgo varchar(4),
@twoYearsAgo varchar(4),
@lastYear varchar(4),
@inTreeYearsAgo varchar(20),
@inTwoYearsAgo varchar(20),
@inLastYear varchar(20),
@outThreeYearsAgo varchar(20),
@outTwoYearsAgo varchar(20),
@outLastYear varchar(20)
set @count = 0;
delete from cw.dbo.CBMtemp;
insert into cw.dbo.CBMtemp (BMH,BMM,FZR)select distinct a.BMH,a.BMM,a.FZR from cwbackup.dbo.CBM a where a.TZ='45' and BMH like '8%' order by a.BMH;
select @count = count(*),BMH from cwbackup.dbo.CBMtemp;
while @count>0
begin
select @inTreeYearsAgo = sum(b.N6),@outTreeYearsAgo = sum(b.N7) from cwbackup.dbo.cwmc2010 b;
select @inTwoYearsAgo = sum(c.N6),@outTwoYearsAgo = sum(c.N7 )from cwbackup.dbo.cwmc2011 c;
select @inLastYear = sum(d.N6),@outLastYear = sum(d.N7) from cwbackup.dbo.cwmc2012 d;
update cwbackup.dbo.CBMtemp set inTreeYearsAgo = @inTreeYearsAgo,
inTwoYearsAgo = @inTwoYearsAgo,
inLastYear = @inLastYear,
outTreeYearsAgo = @outThreeYearsAgo,
outTwoYearsAgo = @outTwoYearsAgo,
outLastYear = @outLastYear;
end
END
提示的错误如下:
消息 102,级别 15,状态 1,过程 cbmtest,第 6 行
'@count' 附近有语法错误。
消息 137,级别 15,状态 1,过程 cbmtest,第 20 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 1,过程 cbmtest,第 23 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 2,过程 cbmtest,第 24 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 1,过程 cbmtest,第 26 行
必须声明标量变量 "@inTreeYearsAgo"。
消息 137,级别 15,状态 1,过程 cbmtest,第 27 行
必须声明标量变量 "@inTwoYearsAgo"。
消息 137,级别 15,状态 1,过程 cbmtest,第 28 行
必须声明标量变量 "@inLastYear"。
消息 137,级别 15,状态 2,过程 cbmtest,第 29 行
必须声明标量变量 "@inTreeYearsAgo"。 展开
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
--ALTER procedure [dbo].[cbmtest]
CREATE PROCEDURE cbmtest
as
begin
SET NOCOUNT ON;
@count int,
@unitID varchar(20),
@projectCodeTag varchar(4),
@threeYearsAgo varchar(4),
@twoYearsAgo varchar(4),
@lastYear varchar(4),
@inTreeYearsAgo varchar(20),
@inTwoYearsAgo varchar(20),
@inLastYear varchar(20),
@outThreeYearsAgo varchar(20),
@outTwoYearsAgo varchar(20),
@outLastYear varchar(20)
set @count = 0;
delete from cw.dbo.CBMtemp;
insert into cw.dbo.CBMtemp (BMH,BMM,FZR)select distinct a.BMH,a.BMM,a.FZR from cwbackup.dbo.CBM a where a.TZ='45' and BMH like '8%' order by a.BMH;
select @count = count(*),BMH from cwbackup.dbo.CBMtemp;
while @count>0
begin
select @inTreeYearsAgo = sum(b.N6),@outTreeYearsAgo = sum(b.N7) from cwbackup.dbo.cwmc2010 b;
select @inTwoYearsAgo = sum(c.N6),@outTwoYearsAgo = sum(c.N7 )from cwbackup.dbo.cwmc2011 c;
select @inLastYear = sum(d.N6),@outLastYear = sum(d.N7) from cwbackup.dbo.cwmc2012 d;
update cwbackup.dbo.CBMtemp set inTreeYearsAgo = @inTreeYearsAgo,
inTwoYearsAgo = @inTwoYearsAgo,
inLastYear = @inLastYear,
outTreeYearsAgo = @outThreeYearsAgo,
outTwoYearsAgo = @outTwoYearsAgo,
outLastYear = @outLastYear;
end
END
提示的错误如下:
消息 102,级别 15,状态 1,过程 cbmtest,第 6 行
'@count' 附近有语法错误。
消息 137,级别 15,状态 1,过程 cbmtest,第 20 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 1,过程 cbmtest,第 23 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 2,过程 cbmtest,第 24 行
必须声明标量变量 "@count"。
消息 137,级别 15,状态 1,过程 cbmtest,第 26 行
必须声明标量变量 "@inTreeYearsAgo"。
消息 137,级别 15,状态 1,过程 cbmtest,第 27 行
必须声明标量变量 "@inTwoYearsAgo"。
消息 137,级别 15,状态 1,过程 cbmtest,第 28 行
必须声明标量变量 "@inLastYear"。
消息 137,级别 15,状态 2,过程 cbmtest,第 29 行
必须声明标量变量 "@inTreeYearsAgo"。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询