Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
gamaz
Posting Yak Master
104 Posts |
Posted - 2009-04-16 : 17:19:42
|
| Hi,I am trying to write a stored procedure that takes the data from cursor processing that stored it in a temporary table. However I am getting an error while compiliing this stored procedure. I appreciate any help for resolution of this problem.CODE:ALTER procedure [dbo].[test_release2]ASset nocount on--Create a temporary table which will stored the result processed in cursorcreate table #tblhrstorun( ID int IDENTITY, mach varchar(50), ordnum varchar(10), hrstorun1 int ) --Declare the cursor declare hrstorun_round cursorfor select mach, ordnum, round(hrstorun, 0) as hrstorun1from tblprojectionold1order by mach--Declare the variables that will hold data for each rowDeclare @ordnum varchar(10), @mach varchar(50), @hrstorun float, @hrstorun1 int, @msgstr varchar(200)--Print the headingPRINT 'MachineNo--------------OrdNum-------------HrsToRun'--Open cursor and fetch the rowsopen hrstorun_round fetch next from hrstorun_round into @mach, @ordnum, @hrstorun1while @@fetch_status = 0BEGIN--Insert the row fetched by cursor to the temporary table insert into #tblhrstorun(mach,ordnum,hrstorun1) (@mach, @ordnum, @hrstorun1) ****** THIS LINE IS THROWING THE ERROR MESSAGEfetch next from hrstorun_round into @mach, @ordnum, @hrstorun1ENDselect * from #tblhrstorunclose hrstorun_rounddeallocate hrstorun_round |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2009-04-16 : 17:24:26
|
| --Insert the row fetched by cursor to the temporary tableinsert into #tblhrstorun(mach,ordnum,hrstorun1)VALUES(@mach, @ordnum, @hrstorun1)<><><><><><><><><><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion |
 |
|
|
gamaz
Posting Yak Master
104 Posts |
Posted - 2009-04-16 : 17:57:48
|
| Thanks yosiasz for the help. I appreciate it. |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-04-16 : 18:44:14
|
| Is this just an exercise to use a cursor? If not, you would be better off using a set-based solution. |
 |
|
|
|
|
|
|
|