0

我可以使用存储过程来诱导系统视图吗?例如我有它:

CREATE PROCEDURE DBO.status_serwer
AS
BEGIN
EXECUTE msdb.dbo.sysmail_help_status_sp
END

Sysmail_help_status 过程返回服务器的状态:'stopped' 或'started' 现在,我可以将 start_serwer 过程作为视图或函数调用吗?有人帮忙吗?

4

1 回答 1

1

好吧,如果你查看那个存储过程,你可以抓住它运行的查询并稍微修改它,这样你就可以在其他地方使用它,就像这样;

SELECT 
    CASE (SELECT COUNT(*) FROM msdb.sys.service_queues WHERE name = N'ExternalMailQueue' AND is_receive_enabled = 1) 
        WHEN 0 THEN 'STOPPED' 
        ELSE 'STARTED' 
        END AS 'sysmail_status'

以下是原文供参考:

ALTER PROCEDURE [dbo].[sysmail_help_status_sp]
  WITH EXECUTE AS 'dbo'
AS
BEGIN
    IF NOT EXISTS (SELECT * FROM sys.service_queues WHERE name = N'ExternalMailQueue' AND is_receive_enabled = 1)
       SELECT 'STOPPED' AS Status
    ELSE
       SELECT 'STARTED' AS Status
END
于 2012-08-10T20:39:44.690 回答