作为SQL作业的一部分执行查询

时间:2016-06-29 13:10:41

标签: sql sql-server-2008

我正在使用以下查询将数据插入表中:

INSERT salesteamactivity.dbo.ProfileScore
    SELECT
        DATEADD(dd, DATEDIFF(d, 0, GETDATE()), 0) AS [Date],
        owneridname AS [Account Manager],
        COUNT(new_cyberessentialsname) AS [Cyber Essentials],
        COUNT(sec1_encryption) AS [Encryption],
        COUNT(sec1_firewallsolutionname) AS [Firewall],
        COUNT(sec1_pcidss) AS [PCI DSS],
        COUNT(sec1_asvscannername) AS [PCI ASV],
        COUNT(sec1_pentestingname) AS [Penetration Testing],
        COUNT(new_phishinsolution) AS [Phishing],
        COUNT(sec1_scannername) AS [Scanner],
        COUNT(sec1_twofactorauthentication) AS [Two Factor Authentication],
        COUNT(1) AS [Relationship Type]
    FROM 
        [SEC1_MSCRM].dbo.[FilteredAccount]
    WHERE 
        customertypecodename = 'Customer' 
        AND statuscodename = 'Active'
    GROUP BY 
        owneridname

如果我将任务作为独立查询运行,则按预期插入数据。如果我将其作为SQL Server代理作业中的一个步骤运行,则虽然脚本解析并且作业成功完成,但数据不会插入。

附上了工作配置的几个屏幕截图。

步骤配置:

enter image description here

一般配置:

enter image description here

此致

0 个答案:

没有答案