Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Working with cursors
Message
From
24/11/2003 04:35:45
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Title:
Working with cursors
Miscellaneous
Thread ID:
00852881
Message ID:
00852881
Views:
37
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
Next
Reply
Map
View

Click here to load this message in the networking platform