我在SQL 2012上度过了一段可怕的时光。我习惯于使用SQL 2000进行作业调度和自动化,但我是2012年的新手。
我编写了一个非常基本的脚本(见下文),无论我做什么,脚本都失败了,作为工作的第一步,但在查询窗口中作为独立查询工作正常。
任何帮助都会有很长的路要走。
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
经过几个小时的努力才能完成这项工作,它仍无法正常工作。我甚至改变了SQL Server代理服务以我的身份运行(域管理员)