Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FETCH same value repeating (again!)
Message
From
13/06/2008 21:44:58
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Title:
FETCH same value repeating (again!)
Miscellaneous
Thread ID:
01324056
Message ID:
01324056
Views:
60
Not sure what I did to this, but now the @ChartID only ever has the value of the first row of the ChartID cursor. There are two places I'm printing it out, the
first is just for debugging, but the second is the actual output I'm looking for. It seems to only use the first ChartID.


UPDATE:

For some reason this line caused a problem. Once I removed it, then all worked fine.
		IF @Filename LIKE '%.doc%'
Set NOCOUNT ON

Declare	@poscode as varchar(10),
			@posdesc as varchar(100),
			@acctno as varchar(20),
			@provcode as varchar(20),
			@PatientID as varchar(25),
			@ChartNumber as varchar(30),
			@ChartID as varchar(30),
			@Last_Name as varchar(30),
			@First_Name as varchar(30),
			@Middle_Initial as varchar(5),
			@Sex	as char(1),
			@DOB as char(10),
			@SSN as char(11),
			@ID as varchar(20),
			@LastName as varchar(30),
			@FirstName as varchar(30),
			@MiddleInitial as varchar(5),
			@Title as varchar(10),
			@Suffix as varchar(10),
			@UPIN as varchar(20),
			@Name as varchar(100),
			@LocID varchar(20),
			@DocDateTime as varchar(8),
			@DocumentName as varchar(80),
			@OldDocDateTime as varchar(22),
			@OldSubject as varchar(80),
			@Filename as varchar(50),
			@path as varchar(50),			
			@page as varchar(10),
			@documentid as varchar(40),
			@SQL as varchar(8000),
			@COPYSCRIPT as nvarchar(4000),
			@CREATEDIRSCRIPT as nvarchar(4000),
			@DELETEDIRSCRIPT as nvarchar(4000),
			@Folder as varchar(100),
			@Export_FileName as varchar(100),
			@CONVERTSCRIPT as nvarchar(4000)

USE ImpactMD

DECLARE
ChartID CURSOR
Forward_Only
	FOR
		SELECT DISTINCT (P.ChartID)
			FROM IMPACTMD.dbo.Patients P
			INNER JOIN IMPACTMD.dbo.Doc_Header H ON H.PatientID = P.PatientID

			-- Testing Only!
--			WHERE ChartID = '1601'
--			WHERE ChartID = '286'


OPEN ChartID

FETCH NEXT
	FROM ChartID
	INTO @ChartID
	WHILE @@FETCH_STATUS = 0

BEGIN

	PRINT @ChartID

	Declare Patient cursor
			Forward_Only
			Read_Only
		For
		SELECT DISTINCT 
			ISNULL(CONVERT(VARCHAR(8),H.DATE,112),'') AS DocumentDate,
			ISNULL(H.DocumentName,''),
			ISNULL(H.documentid,''),
			ISNULL(FT.DESCRIPTION,'')
			FROM IMPACTMD.dbo.Patients P
			INNER JOIN IMPACTMD.dbo.Doc_Header H
			ON H.PatientID = P.PatientID
			INNER JOIN IMPACTMD.dbo.Folder_Template FT
			ON H.FolderID = FT.FolderID
			WHERE P.ChartID = @ChartID

			-- Testing Only!
--			WHERE ChartID = '1601' AND DocumentID = '58275'
--			WHERE ChartID = '286' AND DocumentID = '19428'


	Open Patient
	
	FETCH NEXT
		FROM Patient
		INTO 
			@DocDateTime ,
			@DocumentName,
			@documentid ,
			@Folder 
		WHILE @@FETCH_STATUS = 0

	BEGIN

		DECLARE PAGE CURSOR
		Forward_Only
		Read_Only
		FOR
			SELECT 
				DD.PATH,
				DD.Filename,
				DD.PAGE
				FROM IMPACTMD.dbo.Doc_Detail DD
				WHERE documentid = @documentid
				ORDER BY DD.Filename, DD.PAGE

		OPEN PAGE

		FETCH NEXT
			FROM PAGE
			INTO
				@PATH ,
				@Filename,
				@PAGE
			WHILE @@FETCH_STATUS = 0

		BEGIN

-- Chart number,Image topic name,Image name,Image Date,Image filename

			Print	@ChartID + 
				',' + 
				@DocumentName + 
				',' +
				@DocumentName + 
				',' +
				@DocDateTime + 
				',' + 
				@FileName

			IF @Filename LIKE '%.doc%'

--				Set @CONVERTSCRIPT = 'c:\Tiff\RTFConverter.exe "' + @DocumentID + '|c:\ImpactMD\Export\' + @DocumentID + '.rtf"'
--				Print 'Convert Script - ' + @CONVERTSCRIPT
--				exec master.dbo.xp_cmdshell @CONVERTSCRIPT, no_output

			FETCH NEXT
				FROM PAGE
				INTO 
					@PATH ,
					@Filename,
					@PAGE

		END

		CLOSE PAGE
		DEALLOCATE PAGE

		FETCH NEXT
			FROM Patient
			INTO
				@DocDateTime ,
				@DocumentName,
				@documentid ,
				@Folder

	END

	CLOSE Patient
	DEALLOCATE Patient

	FETCH NEXT
		FROM ChartID
		INTO 
			@ChartID

END

CLOSE ChartID
DEALLOCATE ChartID

SET NOCOUNT OFF
Next
Reply
Map
View

Click here to load this message in the networking platform