Click here to Skip to main content
12,077,351 members (45,425 online)
Rate this:
 
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
RyanDev193.6K
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
ryanb31 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

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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2016
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