Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Working with cursors
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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement