2015-10-14 105 views
3

我有SQL 2012年我已经习惯了作业调度和自动化与SQL 2000一个可怕的时间,但我是新来的20122012 SQL作业问题

我写了一个非常基本的脚本(见下文),无论我做什么脚本都作为工作的第一步失败,但在查询窗口中作为独立查询运行良好。

任何帮助都会走很长的路。

declare @AccountID as int 
declare @ID as int 
declare @SaleDate as datetime 
declare @todaysdate as datetime 
declare @sentdate as datetime 
declare @writeToFile as int 
begin 
set @todaysdate = getdate() 
set @writeToFile = 0 
select @id = ID, @AccountID = AccountID, @SaleDate = SaleDate from TransHeader where Transheader.ID = 19680 
--print @@ROWCOUNT 

select AccountID, max(SurveySent) as "THEFINALDATE" from tbl_survey_email where AccountID = @AccountID AND datediff(dd, SurveySent, @todaysdate) <= 182 Group By AccountID 
set @writeToFile = @@ROWCOUNT 
--print @writeToFile 

if (@writeToFile = 0) 
    begin 

     insert into tbl_survey_email ('AccountID','TransactionID', 'datetime') VALUES (@AccountID, @ID, @SaleDate) 
    end 

end 

enter image description here

enter image description here

后乱投医,使这项工作小时,但仍然没有工作。我甚至改变了SQL Server代理服务作为我运行(域管理)

我甚至改变我的脚本只是插入脚本,但仍然几乎相同的错误。有任何想法吗? enter image description here

enter image description here

enter image description here

+0

你知道,如果有正确的约束条件,你可以将整个工作重新写入一个声明中,对吗? –

回答

4

你必须给NT服务用户的权限来访问数据库中的表。您的Keith用户拥有权限,但NT SERVICE不具备此权限。它应该有权限这样的:

enter image description here

当然,在我的屏幕截图,用户是不完全一样的东西,我认为你是,但你的想法。

+3

或者,更好的是,为该工作设置一个特定的用户。 –