Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Still Cursor Issues 1

Status
Not open for further replies.

Delphin

Programmer
Nov 27, 2001
134
0
0
US
OK, I modified my nested cursor to retrieve this information. Everything is being placed into the temp table first, but I can still get no data from the cursor in the query or in the report.

WHAT am I missing

Code:
Declare @DT datetime
	DECLARE @apDate nvarchar(15)
	declare @ApName nvarchar (100)
	Declare @ApAge int
	Declare @ApPat bigint
	Declare @apAcct bigint
	declare @ApSt nvarchar(15)
	Declare @ApCh bigint
	Declare @ApIP char(10)
	Declare @ApUnit int
	Declare @ApCP nvarchar (15)
	declare @rptdt nvarchar (15)
	set @rptdt = '02/17/05'
	declare @DocID bigint
	declare @olddoc bigint
	set @olddoc = ''
set @rptdt =  ISNULL(CONVERT(nvarchar, @RptDt, 1), '')

	Declare @AptTbl table
		(Starttm datetime,
		dr bigint,
		apptdt nvarchar(15),
		appttime nvarchar(15),
		PName nvarchar(100),
		Page int,
		PNo bigint,
		AcctNO bigint,
		Chair Bigint,
		IP Char(10),
		ConfirmPhone nvarchar(15),
		UTP int)

	Insert @Apttbl
	select Distinct(Starttime), dr, apptdt, Appttime,  [name], age,patientno, accountno, chair,IP, confirmphone, UTP from vappointments where 
			apptdt = @rptdt  order by dr, appttime

select top 1 @olddoc = dr from @apttbl order by dr, appttime
--select * from @AptTbl




			declare acurPat CURSOR for  select * from @apttbl order by dr, appttime

			open AcurPat


			
			while @@FETCH_STATUS = 0
			BEGIN
			--if @olddoc = @docid
			begin
			fetch from acurpat into 
					 @DT,
					@docid,
					 @apdate,
					 @apst, 
					 @apname, 
					 @apage, 
					 @appat, 
					 @apacct, 
					 @apch,
					 @apip, 
					 @apCP, 
					@apUnit
				
			

				select 	@DT,
					@docid,
					 @apdate,
					 @apst, 
					 @apname, 
					 @apage, 
					 @appat, 
					 @apacct, 
					 @apch,
					 @apip, 
					 @apCP, 
					@apUnit

	
			fetch next from acurpat into 
					@DT,
					@docid,
					 @apdate,
					 @apst, 
					 @apname, 
					 @apage, 
					 @appat, 
					 @apacct, 
					 @apch,
					 @apip, 
					 @apCP, 
					@apUnit

			end
			close acurpat
			deallocate acurpat
			end
 
Problem remains the same as before - you have one misplaced FETCH statement:
Code:
... 
open AcurPat

[b]fetch next from AcurPat into @DT, @docID, blah blah[/b]
while @@FETCH_STATUS = 0
begin
	set @olddoc = @docID
	-- process doctor here
	
	while @@FETCH_STATUS = 0 -- and @olddoc = @docid
	begin
		-- process appointment here
	
		fetch next from AcurPat into @DT, @docID, blah blah
	end
end	
close AcurPat
deallocate AcurPat

------
Math problems? Call 0800-[(10x)(13i)^2]-[sin(xy)/2.362x]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top