It's not like that I am having trouble executing my cursors which are enclosed in a stored procedure. But I want to find more efficient way to achieve the same.
Here it goes.
Stored procedure : RawFeed.sql
(runs every 5 minutes)
Set @GetATM = Cursor For
Select DeviceCode,ReceivedOn
From RawStatusFeed
Where CRWR=2 AND Processed=0
Order By ReceivedOn Desc
Open @GetATM
Fetch Next
From @GetATM Into @ATM,@ReceivedOn
While @@FETCH_STATUS = 0
Begin
Set @RawFeed=@ATM+' '+Convert(VarChar,@ReceivedOn,121)+' '+'002307'+' '+@ATM+' : Card Reader/Writer - FAULTY '
Exec usp_pushRawDataAndProcess 1,@RawFeed
Fetch Next
From @GetATM Into @ATM,@ReceivedOn
End
Set @GetATM = Cursor For
Select DeviceCode,ReceivedOn
From RawStatusFeed
Where CRWR=0 AND Processed=0
Order By ReceivedOn Desc
Open @GetATM
Fetch Next
From @GetATM Into @ATM,@ReceivedOn
While @@FETCH_STATUS = 0
Begin
Set @RawFeed=@ATM+' '+Convert(Varchar,@ReceivedOn,121)+' '+'002222'+' '+@ATM+' : Card Reader/Writer - OK '
Exec usp_pushRawDataAndProcess 1,@RawFeed
Fetch Next
From @GetATM Into @ATM,@ReceivedOn
End
Likewise I have 10 more SET
statements which differ on WHERE
condition parameter & string enclosed in @RawFeed
variable.
For each row I get I execute another stored procedure on that particular row.
My question is
Is there any better way to achieve the same without using cursors?
Variable @RawFeed
Contains following string
which is input to usp_pushRawDataAndProcess
stored procedure. now this will divide whole string and do some operation like INSERT,UPDATE,DELETE
on some tables.
WE JUST CAN NOT PROCESS MORE THAN 1 STRING IN usp_pushRawDataAndProcess
NMAAO226 2012-09-22 16:10:06.123 002073 NMAAO226 : Journal Printer - OK
WMUAO485 2012-09-22 16:10:06.123 002222 WMUAO485 : Card Reader/Writer - OK