Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem related to cursor when it used some error occurred my code is below
SQL
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

SQL
@tempTax=@tempTax+@xtemp


the error comes on above line
Posted
Updated 14-Feb-13 2:44am
v2
Comments
Sandeep Mewara 14-Feb-13 8:33am    
Try giving space in between them. Specially before and after + sign. See if that helps.
Dharmendra-18 14-Feb-13 22:35pm    
already do this but not effect
ZurdoDev 14-Feb-13 8:43am    
What's the error?
Dharmendra-18 14-Feb-13 22:36pm    
Incorrect syntax near '@tempTax'.
on
@tempTax=@tempTax+@xtemp

line

1 solution

The error message your are getting is
Msg 170, Level 15, State 1, Procedure REP_Purchase_Monthly, Line 22
Line 22: Incorrect syntax near '@tempTax'.

You need the word SET before the assignment i.e.
SQL
SET @tempTax=@tempTax+@xtemp

You'll need the same fix on subsequent lines too
 
Share this answer
 
Comments
Dharmendra-18 14-Feb-13 22:45pm    
thanks the problem is solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900