I have SQL Server sp using a cursor like this:
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 works fine, but it would be nice to check if the cursor query has any records before continuing to process it. if there is @@ var, which can I use to verify this? I know there is @@ RowCount - but this only has the current number of rows processed - therefore not very useful
Ideally, I would like to do something like this:
if @@cursorQueryHasRecords
BEGIN
WHILE @@FETCH_STATUS = 0
BEGIN
...etc
thank
physical
source
share