我編寫了一個SQL腳本來將名稱映射到報告名稱。我已在我的本地SQL Server 2012計算機中進行驗證。它運作良好。然而,當我在服務器上運行,我得到了錯誤爲什麼SQL腳本可以在本地環境中運行,但無法在其他服務器上運行
消息537,級別16,狀態3,行40
傳遞給左或子字符串函數無效長度參數。
我也嘗試直接在遠程服務器上運行「select」部分,結果也是正確的。 我不明白爲什麼它是錯誤的。有什麼想法? (注:我補充「錯誤的位置 - >」中的錯誤行)
DECLARE @jobTable TABLE
(
job_name nvarchar(max),
report_name nvarchar(max),
event_type nvarchar(max),
description nvarchar(max),
last_run_date int,
last_run_time int
)
declare
@job_name uniqueidentifier,
@report_name nvarchar(max),
@event_type nvarchar(max),
@description nvarchar(max),
@last_run_date int,
@last_run_time int,
@last_run_dur int
/************** alert ********/
declare getId_alertjob_cursor cursor for (
SELECT
[jobs].[name] job_name,
alertFeed.relativePath report_name,
CONVERT(nvarchar(max), SUBSTRING([steps].[command], CHARINDEX(' @EventType=''', [steps].[command], 0) + LEN(' @EventType='''), CHARINDEX('''', [steps].[command], CHARINDEX(' @EventType=''', [steps].[command]) + LEN(' @EventType=''')) - CHARINDEX(' @EventType=''', [steps].[command], 0) - LEN(' @EventType=''')), 0) event_type,
[steps].[last_run_date] last_date,
[steps].[last_run_time] last_time,
[steps].[last_run_duration] last_dur
FROM [msdb].[dbo].[sysjobs] [jobs] INNER JOIN [msdb].[dbo].[sysjobsteps] [steps] ON [jobs].[job_id] = [steps].[job_id], ReportingService_4c0ed75e1e8c4e50acbf853867f071f3_Alerting.dbo.AlertDefinition [alertDef], ReportingService_4c0ed75e1e8c4e50acbf853867f071f3_Alerting.dbo.Feed [alertFeed]
WITH (NOLOCK)
WHERE [jobs].[name] <> 'syspolicy_purge_history'
and alertDef.scheduleid = CONVERT(nvarchar(max), SUBSTRING([steps].[command], CHARINDEX(' @EventData=''', [steps].[command], 0) + LEN(' @EventData='''), CHARINDEX('''', [steps].[command], CHARINDEX(' @EventData=''', [steps].[command]) + LEN(' @EventData=''')) - CHARINDEX(' @EventData=''', [steps].[command], 0) - LEN(' @EventData=''')), 0)
and alertDef.FeedId = alertFeed.FeedId
);
open getId_alertjob_cursor
error here--> fetch next from getId_alertjob_cursor INTO @job_name, @report_name, @event_type, @last_run_date, @last_run_time, @last_run_dur
while @@FETCH_STATUS = 0
BEGIN
-- INSERT INTO @jobTable VALUES (@job_name, @report_name, @event_type,'Alert',0,0);
-- ,@last_run_date,@last_run_time);
fetch next from getId_alertjob_cursor INTO @job_name, @report_name, @event_type, @last_run_date, @last_run_time,@last_run_dur
END
close getId_alertjob_cursor
deallocate getId_alertjob_cursor
是的,他們都是MS SQL服務器2012 – user1504146 2013-04-24 09:28:06
您是否傳遞相同的一組參數? – Maximus 2013-04-24 09:34:04