-
Hi
I have a declared cursor this way:
CREATE PROCEDURE mystore AS
declare @EmpId integer
declare @worder int
declare @wcliente nchar(4)
declare @wFunc int
declare @wdata datetime
declare mycursor SCROLL cursor
for
select orderid,customerid,EmployeeId,orderdate
from orders
where EmployeeId = @EmpId
select @EmpId =3
while @EmpId<=4
begin
open mycursor
fetch next from mycursor into @worder,@wcliente ,@wfunc,@Wdata
while @@fetch_status = 0
begin
print @worder
fetch next from mycursor into @worder,@wcliente ,@wfunc,@Wdata
end
close mycursor
select @EmpId = @EmpId +1
print @EmpId
end
close mycursor
deallocate mycursor
I want to vary the variable @EmpId, this routine is only a test to see if it works, I caught these data of the bank NORTHWIND of the table ORDERS. Doesn't he come back any given, what is wrong?
I am in advance grateful
-
This is what I get from running your query:
4
5
Server: Msg 16917, Level 16, State 1, Procedure mystore, Line 29
Cursor is not open.
What are you trying to do?
-
Hi
I want that the cursor do it , conforming the variable @EmpID
-
-
And why are you using cursors? Nothing sez slow like using a cursor when you don't need to...
-
Hi
Thank you for the attention, which I passed, it was just an example.
I am using cursor because I am setting up schedules that they are come back, example
hr_ini hr_fim
07:00 07:04
07:05 07:09
.......
07:55 07:59
11:00 11:04
11:05 11:09
......
I need to diffuse continuous schedules between a hr_fim and the neighbor's hr_ini, in the example above see that hr_ini = 07:05 and previous hr_fim = 07:04 are just one minute, while this difference goes 1 minute I am going keeping the first hr_ini, that is hr_ini=07:00 until the interval between hr_fim and the neighbor's hr_ini in the case it is larger than 1, as it happens in hr_fim =07:59 and hr_ini = 11:00 When there is this break of schedules I leave a loop and I set up schedules of agreement the duration of an event, in the example my initial schedule was above being 07:00 and final schedules 07:59, if the event lasted 0:15 minutes, the picture would be like this:
07:00 07:15
07:15 07:30
07:30 07:45
07:45 07:59 (or 08:00 increased 1 minute in 07:59)
Done this now my initial schedule it would be 11:00 and it would continue the process.
My problem is that this calendar is set up of agreement the day certain procedure, example, has procedures that It has only Monday or only Wednesday, and when a date is passed for Stored Procedure I verify which is the day of the week, and in this I have been setting up a CURSOR, like this SELECT <COMMANDS> FROM TABLES WHERE...... AG02_day_week = @Wday_week, in case I doesn't have this event in that date that was last for the procedure I increase one day in the date and I verify the day of the week and I wanted that the cursor understands that @Wday_week changed. Is It Possible?
The Example that I ordered, is exactly to see this, moving the variable the cursor understands this change
thank you in advance
-
I'm still not clear on exactly what you're trying to do But I am curious, is this going to be a stored procedure solution or do you have the flexibility to do a laguage solution VB6 (for example). The reason I ask is because it appears that what you are trying to do would be more suited to a recordset loop in VB than cursors
[Edited by JHausmann on 06-05-2000 at 01:44 PM]