声明光标并在过程中使用 [英] Declaring Cursor and using in Procedure

查看:114
本文介绍了声明光标并在过程中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与光标相关的问题,当它使用了一些错误时我的代码在下面

I have a problem related to cursor when it used some error occurred my code is below

create procedure REP_Purchase_Monthly
@stDate varchar(50),@enDate varchar(50)
as
begin
Declare @NumBill int
Declare @TaxVal varchar(50)
Declare @TotalVal varchar(50)
Declare @tempTax int
Declare @tempTotal int
Set @tempTax=0
Set @tempTotal=0
Declare curst Cursor 
for Select Tax,Total from Purchase_Main where CAST(InvoiceDate as Datetime) between 
CAST(@stDate as Datetime) and CAST(@enDate as Datetime)
open curst
FETCH NEXT FROM curst INTO @TaxVal,@TotalVal
while @@FETCH_STATUS = 0
begin
Declare @xtemp int
Set @xtemp=Cast(@TaxVal as Integer)
Declare @xtemps int
Set @xtemps=Cast(@TotalVal as Integer)
  @tempTax=@tempTax+@xtemp
  @tempTotal=@tempTotal+@xtemps
  Fetch next from curst into @TaxVal,@TotalVal
end
Close curst
Deallocate curst
set @NumBill=(Select COUNT(*) from Purchase_Main where CAST(InvoiceDate as Datetime) between 
CAST(@stDate as Datetime) and CAST(@enDate as Datetime))
end





生产线上的问题是





the problems on the line is

@tempTax=@tempTax+@xtemp





上面出现错误line



the error comes on above line

推荐答案

您收到的错误消息是
Msg 170, Level 15, State 1, Procedure REP_Purchase_Monthly, Line 22
Line 22: Incorrect syntax near ''@tempTax''.



在分配之前需要单词SET,即


You need the word SET before the assignment i.e.

SET @tempTax=@tempTax+@xtemp



你会的在后续行上也需要相同的修复


You''ll need the same fix on subsequent lines too


这篇关于声明光标并在过程中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆