Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: SQL Cursor


Message #1 by "Takuya Matsumoto" <takuya@e...> on Tue, 9 Jan 2001 19:02:30 -0000
--0-1769771489-979130278=:78887
Content-Type: text/plain; charset=us-ascii


Takuya

This Works

DECLARE @str_UserID varchar(3)
DECLARE HourCheckCursor CURSOR FOR 
SELECT DISTINCT UserID FROM tblbulletins;
OPEN HourCheckCursor;
 FETCH NEXT FROM HourCheckCursor 
 PRINT @str_UserID
BEGIN
 WHILE ( @@FETCH_STATUS = 0 )
  FETCH NEXT FROM HourCheckCursor
  PRINT @str_UserID
  
 END
CLOSE HourCheckCursor;

DEALLOCATE HourCheckCursor



The first fetch is necessary to place the cursor at the first record
Else the  @@FETCH_STATUS    will be incorrect.

Roland
  Takuya Matsumoto <takuya@e...> wrote: 





Hi,
 
I am not quite used to using cursor on the SQL Server we use.
the script below working, but every time I run it on the Query Analyzer, it only says that the commands compelted successfully and
does not show the results except the first time the file is run.
I've been having to close and reopen the file every time I make a change.
Any idea what I can do?
 
Cheers,
 
Takuya Matsumoto
 
 
#######################################################
 
DECLARE HourCheckCursor CURSOR FOR SELECT userID FROM tbl_user;
OPEN HourCheckCursor;
 WHILE ( @@FETCH_STATUS = 0 )
 BEGIN
  FETCH NEXT FROM HourCheckCursor INTO @str_UserID;
  IF @@FETCH_STATUS = 0
   PRINT @str_UserID;
 END
CLOSE HourCheckCursor;
DEALLOCATE HourCheckCursor;


#######################################################---
To unsubscribe send a blank email to leave-sql_language-$subst('Recip.MemberIDChar')@p2p.wrox.com



---------------------------------
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!

---
You are currently subscribed to sql_language as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-sql_language-$subst('Recip.MemberIDChar')@p2p.wrox.com



  Return to Index