[Racine des codes] [Page précédente]

MS-SQL - Cursor

/SQL/MS-SQL - Cursor.sql
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

DECLARE @lh_id INTEGER;
DECLARE @lh_nom VARCHAR(255);

DECLARE curs CURSOR GLOBAL FORWARD_ONLY FOR
SELECT DISTINCT lh_id, lh_nom
FROM contrat_proprietaire copo
WHERE (...)

OPEN curs;
FETCH NEXT FROM curs INTO @lh_id, @lh_nom;
WHILE (@@FETCH_STATUS = 0)
BEGIN
  EXEC sp_envoi_alerte 'lh_id=' + CAST(@lh_id AS VARCHAR)
  FETCH NEXT FROM curs INTO @lh_id, @lh_nom;
END
CLOSE curs;
DEALLOCATE curs;
[edit]