Pages

Men

rh

10/04/2013

Cursor Example in SQL Server

I HAVE TABLE TABLE CALLED ERRDETAILS  

THE TABLE CONTAINS FOLLOWING DATA



DECLARE @JOBNO INT
DECLARE @NOOFITEMS INT
DECLARE @QTY BIGINT

DECLARE CUR_ERRORDETAILS CURSOR FOR
SELECT JOBNO,NOOFITEMS,QTY FROM  dbo.ERRDETAILS
OPEN CUR_ERRORDETAILS

FETCH NEXT FROM  CUR_ERRORDETAILS INTO  @JOBNO,@NOOFITEMS,@QTY

WHILE @@FETCH_STATUS =0
BEGIN
  
 PRINT 'JOB NUMBER IS...'+ + CONVERT(VARCHAR,@JOBNO)
PRINT 'NO OF ITEMS ARE....'++ CONVERT(VARCHAR,@NOOFITEMS)
PRINT 'QUANTITY IS.....'++ CONVERT(VARCHAR,@QTY)
PRINT '..........................'
FETCH NEXT FROM CUR_ERRORDETAILS INTO @JOBNO,@NOOFITEMS,@QTY
END
CLOSE CUR_ERRORDETAILS
DEALLOCATE CUR_ERRORDETAILS

When i execute this procedure i am going get the following result.

No comments :

Post a Comment