Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Working with cursors
Message
De
24/11/2003 04:35:45
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Working with cursors
Divers
Thread ID:
00852881
Message ID:
00852881
Vues:
38
I know how to create a cursor and print to screen, however I need to be able to use these cursors as an output to excel and also as columns instead of rows. The code used is set out below, can anyone expand on this?


DECLARE @startdate DATETIME, @enddate DATETIME

DECLARE Over_cursor CURSOR FOR
SELECT ah_date
FROM actionhistory ah
INNER JOIN actions ON ac_id = ah_actionid
WHERE ah_claimid = (SELECT cl_id FROM claim WHERE cl_clref '0001')
AND ac_short = 'VOVERPAY'
ORDER BY ah_date

OPEN Over_cursor

-- Get the first date
FETCH NEXT FROM Over_cursor
INTO @startdate
FETCH NEXT FROM Over_cursor
INTO @enddate

WHILE @@FETCH_STATUS = 0
BEGIN

PRINT 'Start date'
PRINT @startdate
PRINT 'End date'
PRINT @enddate
PRINT ''

SET @startdate = @enddate
FETCH NEXT FROM Over_cursor
INTO @enddate

IF @@FETCH_STATUS <> 0
BEGIN
SET @enddate = GETDATE()
END

END

PRINT 'Start date'
PRINT @startdate
PRINT 'End date'
PRINT @enddate
PRINT ''

CLOSE Over_cursor
DEALLOCATE Over_cursor
GO
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform