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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Print doesn't work in Query Analyzer

Author  Topic 

gchacko
Starting Member

8 Posts

Posted - 2002-09-30 : 16:07:22
I have tried simple print statements and it works.
Eg:
DECLARE @CheckCnt int
SELECT @CheckCnt=COUNT(*) FROM Table1
print @CheckCnt

This prints the count.
Now if I try this it doesn't print at all. ????
Eg:
DECLARE @Record_Identifier char(1)
DECLARE Cursor1 CURSOR FOR
SELECT Record_Identifier FROM Table1

OPEN Cursor1
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Cursor1
INTO @Record_Identifier
PRINT @Record_Identifier
END
CLOSE Cursor1
DEALLOCATE Cursor1

1fred
Posting Yak Master

158 Posts

Posted - 2002-09-30 : 16:59:43
just try to print something like print 'hello'
to see if the problem is in the print function or in the cursor or variable

Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2002-09-30 : 17:11:36
Or, maybe move the PRINT statement to before the FETCH NEXT:

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Record_Identifier
FETCH NEXT FROM Cursor1
INTO @Record_Identifier

END
Go to Top of Page

LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2002-09-30 : 17:47:50
The value of @@FETCH_STATUS is undefined before any fetches have occurred on the connection. This means that you never enters the while loop.


Go to Top of Page
   

- Advertisement -