sql server 2012
我有一個過程來包裝sp_help_jobhistory的輸出。存儲過程執行該執行的時候沒有問題,但返回錯誤:sp_help_jobhistory WITH RESULT SETS錯誤
SET FMTONLY OFF
EXEC msdb.dbo.sp_describe_first_result_set @tsql = N'exec msdb.dbo.sp_help_jobhistory_with_results'
GO
這是我得到的錯誤:
Msg 11512, Level 16, State 1, Procedure sp_describe_first_result_set, Line 1 [Batch Start Line 3]
The metadata could not be determined because the statement 'EXEC msdb.dbo.sp_help_jobhistory
@job_id
,@job_name
,@step_id
,@sql_message_id
,@sql' in procedure 'sp_help_jobhistory_with_results' is not compatible with the statement 'EXEC msdb.dbo.sp_help_jobhistory
@job_id
,@job_name
,@step_id
,@sql_message_id
,@sql' in procedure 'sp_help_jobhistory_with_results'.
我在做什麼錯? 下面是代碼
use msdb
go
create proc [dbo].[sp_help_jobhistory_with_results]
@job_id uniqueidentifier=null
,@job_name sysname=null
,@step_id int=null
,@sql_message_id int=null
,@sql_severity int=null
,@start_run_date int=null
,@end_run_date int=null
,@start_run_time int=null
,@end_run_time int=null
,@minimum_run_duration int=null
,@run_status int=null
,@minimum_retries int=null
,@oldest_first int=0
,@server nvarchar(30)=null
,@mode varchar(7)='SUMMARY'
AS
BEGIN
IF (@mode <>'SUMMARY' and (@job_name is not null or @step_id is not null))
BEGIN
-- returns 17 columns
EXEC msdb.dbo.sp_help_jobhistory
@job_id
,@job_name
,@step_id
,@sql_message_id
,@sql_severity
,@start_run_date
,@end_run_date
,@start_run_time
,@end_run_time
,@minimum_run_duration
,@run_status
,@minimum_retries
,@oldest_first
,@server
,@mode
WITH RESULT SETS
(
(
instance_id int
,job_id uniqueidentifier
,job_name sysname
,step_id int
,step_name sysname
,sql_message_id int
,sql_severity int
,[message] nvarchar(1024)
,run_status int
,run_date int
,run_time int
,run_duration int
,operator_emailed nvarchar(20)
,operator_netsent nvarchar(20)
,operator_paged nvarchar(20)
,retries_attempted int
,[server] nvarchar(30)
)
)
END
-- returns 11 columns
ELSE
BEGIN
EXEC msdb.dbo.sp_help_jobhistory
@job_id
,@job_name
,@step_id
,@sql_message_id
,@sql_severity
,@start_run_date
,@end_run_date
,@start_run_time
,@end_run_time
,@minimum_run_duration
,@run_status
,@minimum_retries
,@oldest_first
,@server
,@mode
WITH RESULT SETS
(
(
job_id uniqueidentifier
,job_name sysname
,run_status int
,run_date int
,run_time int
,run_duration int
,operator_emailed nvarchar(20)
,operator_netsent nvarchar(20)
,operator_paged nvarchar(20)
,retries_attempted int
,[server] nvarchar(30)
)
)
END
END
我跟着這裏的示例[https://blogs.msdn.microsoft.com/sqlagent/2012/07/12/workaround-sql-server-2012-openrowset-on-sp_help_job-throws-the-metadata-能而不是待確定/(https://blogs.msdn.microsoft.com/sqlagent/2012/07/12/workaround-sql-server-2012-openrowset-on-sp_help_job-throws-the-metadata-無法確定/) 它不需要指定'WITH RESULT SETS' –
確定@ToDo但它沒有正常工作?您是否嘗試過使用結果集? – scsimon
上述鏈接中的示例沒有指定'WITH RESULT SETS'。 您的建議適用於我的。我不知道我和他有什麼不同。 –