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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print from Query Analyzer

Status
Not open for further replies.

mc81773

Programmer
Sep 19, 2002
6
US
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
 
You need to do your first fetch before you enter your loop.

DECLARE @Record_Identifier char(1)
DECLARE Cursor1 CURSOR FOR
SELECT Record_Identifier FROM Table1

OPEN Cursor1
FETCH NEXT FROM Cursor1 INTO @Record_Identifier
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM Cursor1
INTO @Record_Identifier
PRINT @Record_Identifier
END
CLOSE Cursor1
DEALLOCATE Cursor1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top