Page 119 - CITS - Computer Software Application -TT
P. 119

COMPUTER SOFTWARE APPLICATION - CITS






















           4  --Declare and set counter.
           5  DECLARE @Counter INT
           6  SET @Counter = 1
           7

           8  --Declare a cursor
           9  DECLARE PrintCustomers CURSOR
           10 FOR
           11 SELECT id, c_name, city FROM customer

           12
           13 --Open cursor
           14 OPEN PrintCustomers
           15
           16 --Fetch the record into the variables.
           17 FETCH NEXT FROM PrintCustomers INTO

           18 @id, @c_name, @city
           19
           20 --LOOP UNTIL RECORDS ARE AVAILABLE.
           21 WHILE @@FETCH_STATUS = 0

           22 BEGIN
           23 IF @Counter = 1
           24 BEGIN
           25 PRINT ‘id’ + CHAR(9) + ‘c_name’ + CHAR(9) + CHAR(9) + ‘city’
           26 PRINT ‘--------------------------’

           27 END
           28
           29 --Print the current record
           30 PRINT CAST(@id AS NVARCHAR(10)) + CHAR(9) + @c_name + CHAR(9) + CHAR(9) + @city

           31
           32 --Increment the counter variable
           33 SET @Counter = @Counter + 1
           34



                                                           106

                              CITS : IT&ITES - Computer software application - Lesson 18 - 36
   114   115   116   117   118   119   120   121   122   123   124