首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含结果集的sp_help_jobhistory错误

包含结果集的sp_help_jobhistory错误
EN

Stack Overflow用户
提问于 2016-08-25 01:57:15
回答 2查看 1.1K关注 0票数 1

sql server 2012

我有一个包装sp_help_jobhistory输出的过程。存储过程执行时没有问题,但在执行以下命令时返回错误:

代码语言:javascript
复制
SET FMTONLY OFF
EXEC msdb.dbo.sp_describe_first_result_set @tsql = N'exec msdb.dbo.sp_help_jobhistory_with_results'
GO

这是我得到的错误:

代码语言:javascript
复制
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'.

我做错了什么?以下是代码

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

发布于 2016-08-25 04:03:29

不使用WITH RESULT SETS就无法确定来自sp_help_jobhistory_with_resultsMETADATA,就像您在main过程中所做的那样。改用这个(你必须填写这些列)

代码语言:javascript
复制
EXEC msdb.dbo.sp_describe_first_result_set @tsql = N'exec msdb.dbo.sp_help_jobhistory_with_results with result sets ((Col1 datatype, Col2 datatype, etc....))'
票数 1
EN

Stack Overflow用户

发布于 2016-08-25 04:06:44

Raises an error if the Database Engine cannot determine the metadata for the first query that will be executed by performing a static analysis. https://msdn.microsoft.com/en-us/library/ff878602.aspx的系统存储过程

我以前没有使用过这个存储过程,所以我不知道为什么需要运行它。我没有看到任何证据表明它是针对存储过程运行的。http://stevestedman.com/2013/04/t-sql-2012-procedure-sp_describe_first_result_set/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39130051

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档