CREATE PROCEDURE DBO.GetJobIDs AS
SET NOCOUNT ON
/*
  DEPRECATED! WHY NOT JUST DO THIS IN DELPHI CODE AND WHY A CURSOR?


   Created by Jacob Pedersen 14-03-2002
   JP 20040420 enabled=1 and removed old where because it fails at IDA and is not really needed
   FEH 20020320

*/

DECLARE @job_id UNIQUEIDENTIFIER
DECLARE @name varchar (100)
DECLARE @job_id_as_char VARCHAR(36)

CREATE TABLE #tmptable (job_id_char VARCHAR(36) not null,
                                             name VARCHAR (100) not null)

DECLARE #JobCur CURSOR FORWARD_ONLY FOR

SELECT job_id, name FROM msdb.dbo.sysjobs
WHERE (Enabled=1)
/*   (owner_sid = SUSER_SID())
   OR (ISNULL(IS_SRVROLEMEMBER(N'sysadmin'), 0) = 1)
   OR (ISNULL(IS_MEMBER(N'TargetServersRole'), 0) = 1)*/

OPEN #JobCur

FETCH NEXT FROM #JobCur INTO @job_id, @name

WHILE  (@@FETCH_STATUS <> -1)
BEGIN
--  EXEC msdb.dbo.sp_convert_jobid_to_char @job_id,  @job_id_as_char OUTPUT

  SET @job_id_as_char = CONVERT (VARCHAR (36), @job_id)

  INSERT INTO #tmptable (job_id_char, name) VALUES (@job_id_as_char, @name)

  FETCH NEXT FROM #JobCur INTO @job_id, @name
END

SELECT * FROM #tmptable
DROP TABLE #tmptable

CLOSE #JobCur
DEALLOCATE #JobCur

