Click here to Skip to main content
11,411,312 members (65,347 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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

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

line

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
SET @tempTax=@tempTax+@xtemp
You'll need the same fix on subsequent lines too
  Permalink  
Comments
Dharmendra-18 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 149
1 Sascha Lefévre 110
2 OriginalGriff 103
3 Dave Kreskowiak 80
4 Maciej Los 78
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,983
2 Maciej Los 3,430
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100