I have a SQL Server sp using a cursor thus:
DECLARE TestCursor CURSOR FOR
SELECT
tblHSOutcomes.strOutcomeName,
tblHSData.fkHSTest
FROM
tblHSData
INNER JOIN tblHSOutcomes ON tblHSData.fkOutcome = tblHSOutcomes.uidOutcome
INNER JOIN tblHSTests ON tblHSData.fkHSTest = tblHSTests.uidTest
WHERE
tblHSData.fkEpisode = @uidHSEpisodes
OPEN TestCursor
FETCH NEXT FROM TestCursor
INTO @Result, @TestID
WHILE @@FETCH_STATUS = 0
BEGIN
...etc
It's working fine , however it would be nice to be able to check if the cursors query has any records before continuing to process through it.
if there a @@
var that I can use to check this?
I know there is @@RowCount
- but this has only the current number of rows processed - so isn't very helpful
Ideally I would like to be able to do something like this:
if @@cursorQueryHasRecords
BEGIN
WHILE @@FETCH_STATUS = 0
BEGIN
...etc
thanks