I do not write cursors very often, but this time I have to. How do you get a nested cursor to work without the error that the cursor already exists or that it is already open?
Here is my code:
Have no clue. tried this several different ways but cannot get it to run or select any rows.
Here is my code:
Code:
Declare @DT datetime
DECLARE @apDate nvarchar(20)
declare @ApName nvarchar (150)
Declare @ApAge int
Declare @ApPat bigint
Declare @apAcct bigint
declare @ApSt nvarchar(20)
Declare @ApCh as Char (10)
Declare @ApIP nvarchar(10)
Declare @ApUnit nvarchar(10)
Declare @ApCP nvarchar (15)
declare @rptdt nvarchar (15)
set @rptdt = '02/17/05'
declare @DocID bigint
declare acurDoc cursor for select distinct(dr) from VAppointments where ApptDt = ISNULL(CONVERT(nvarchar, @RptDt, 1), '')
while @@FETCH_STATUS = 0
BEGIN
Open AcurDoc
fetch next from acurdoc into @docid
select @docid
select @rptdt
select Distinct(Starttime), dr, apptdt, Appttime, [name], age,patientno, accountno, chair,IP, confirmphone, UTP from vappointments where
@DT = ISNULL(CONVERT(nvarchar, @RptDt, 1), '')/* and Dr = @docID*/ order by dr, appttime
declare acurPat CURSOR for select Distinct(Starttime), dr, apptdt, Appttime, [name], age,patientno, accountno, chair,IP, confirmphone, UTP from vappointments where
@DT = ISNULL(CONVERT(nvarchar, @RptDt, 1), '')/* and Dr = @docID*/ order by dr, appttime
open AcurPat
while @@FETCH_STATUS = 0
BEGIN
fetch next from acurpat into
@DT,
@docid,
@apdate,
@apname,
@apage,
@appat,
@apacct,
@apst,
@apch,
@apip,
@apUnit,
@apCP
select @DT,
@apdate,
@apname,
@apage,
@appat,
@apacct,
@apst,
@apch,
@apip,
@apUnit,
@apCP
fetch next from acurpat into
@DT,
@docid,
@apdate,
@apname,
@apage,
@appat,
@apacct,
@apst,
@apch,
@apip,
@apUnit,
@apCP
END -- patient loop
close acurpat
deallocate acurpat
fetch next from Acurdoc into @docid
END --Doctor loop
close acurdoc
deallocate acurdoc
Have no clue. tried this several different ways but cannot get it to run or select any rows.