Sunday, 2 October 2011

MsSqlserver 2008 Cursor Example


DECLARE @RevFormatID INT
DECLARE @Centerid INT

DECLARE  @vin CURSOR
SET @vin= CURSOR  FOR  
SELECT DISTINCT ReportingCenterID
FROM vCenterSelect           
WHERE ISNULL(RevFormatID,1)=  1

OPEN @vin             
             
FETCH NEXT             
FROM @vin INTO @CenterId 
WHILE @@FETCH_STATUS = 0         
BEGIN   

SELECT UserId,CenterID from TblUserCenterMapping WHERE CenterID=@Centerid
            
FETCH NEXT             
FROM @vin INTO @CenterId   
END             
CLOSE @vin             
DEALLOCATE @vin

No comments:

Post a Comment