Previous Topic

Next Topic

Inhoudsopgave

Book Index

Variable Binding In Cursors

If you have a cursor definition including variables, in ASE, the variables are evaluated run time during the ‘open’ statement. In MS SQL Server, the variables are evaluated run time during the ‘declare’ statement.

Example

create proc SelDossiersByDate as

begin

declare @ADate DateTime, @DossierCode T_Code_Dossier

declare cr_DossiersOnDate cursor for

select DossierCode from T_DossierMain

where QuotDate = @ADate

order by DossierCode

select @ADate = '2000-10-27'

open cr_DossiersOnDate

fetch cr_DossiersOnDate into @DossierCode

while @@SQLStatus = 0 -- while @@Fetch_Status = 0

begin

select @DossierCode

fetch cr_DossiersOnDate into @DossierCode

end

close cr_DossiersOnDate

deallocate cursor cr_DossiersOnDate -- deallocate cr_DossiersOnDate

end

go

exec SelDossiersByDate

go

drop proc SelDossiersByDate

go

On ASE, the example above returns the DossierCodes of the dossiers having the 27th of October 2000 as a quotation date. On MS SQL Server, the DossierCodes of the dossiers without a quotation date (= NULL) are returned.