我有一个多步工作,已经好几个月了。突然之间,它在第5步失败了。如果我在查询分析器中运行步骤5的tsql,它就可以了。有什么想法吗?以下是我正在使用的代码。
MERGE BISS..tblBoxInfo AS target
USING ( SELECT BX.BOX_BOXNO, BX.BOX_UDF_AIRR_BOXNO, CONVERT(VARCHAR(510), BX.BOX_DESC),
--RTRIM(STUFF(CONVERT(VARCHAR(510),BOX_DESC), 1,
PATINDEX(N'%[^' + CHAR(9)+CHAR(10)+CHAR(13)+CHAR(32) + N']%', BOX_DESC)-1, N' '))
BX.BOX_UDF_NARA_LOCATION, CONVERT(VARCHAR(6),DP.DEPT_ID),
DP.DEPT_NAME, BX.BOX_UBN, BX.BOX_RCID, CONVERT(VARCHAR(15),CLV.CLV_TITLE),
BX.BOX_DT_CREATION,
CONVERT(VARCHAR(MAX), BX.BOX_UDF_TRIBES),--was NOS = CASE BOX_SROOM_INDEX WHEN 19 THEN 1 ELSE 0 END,
BX.BOX_DT_FROM, BX.BOX_DT_TO, SS.SROOM_ID
FROM ISTAbq3Ver01.VssEnt.dbo.BOXES BX
LEFT JOIN ISTAbq3Ver01.VssEnt.dbo.DEPTS DP
ON DP.DEPT_ID_FULL = BX.BOX_DEPT
LEFT JOIN ISTAbq3Ver01.VssEnt.dbo.SROOMS SS
ON SS.SROOM_AUTO_INDEX = BX.BOX_SROOM_INDEX
LEFT JOIN ISTAbq3Ver01.VssEnt.dbo.CUSTOM_LISTS_VALUES CLV
ON CLV.CLV_AUTO_INDEX = BX.BOX_UDF_AIRR_WORKSITE
WHERE NOT ( SS.SROOM_ID IN (
N'MP',
N'INDEX',
N'QC1',
N'QC2',
N'NTEMP',
N'SF135',
N'SFPREP',
N'NOS',
N'RR',
N'NTEMP2',
N'OHTA',
N'DUPS 36',
N'RSH',
N'DISC',
N'NARAT',
N'TRANS',
N'ABQ')
OR SS.SROOM_ID LIKE N'PGRS-%')
--WHERE SS.SROOM_ID IN (N'NOS', N'NARA')
-- OR SS.SROOM_ID LIKE 'SL%'
/*ORDER BY BOX_BOXNO */) AS source
(BoxID,BoxNum,BoxTitle,BoxLocation,BoxSourceCode,BoxSource,OST,FRC,WorkSite,dtLoaded,TribeInfo,dtFrom,dtTo, BoxStatus)
ON (target.BoxID = source.BoxID)
WHEN MATCHED AND (target.BoxNumber != source.BoxNum
OR target.BoxTitle != source.BoxTitle
OR target.BoxLocation != source.BoxLocation
OR target.BoxSourceCode != source.BoxSourceCode
OR target.BoxSource != source.BoxSource
OR target.OSTNumber != source.OST
OR target.FRCNumber != source.FRC
OR target.WorkSite != source.WorkSite
OR target.LoadedDate != source.dtLoaded
OR target.TribeInfo != source.TribeInfo
OR target.From_Date != source.dtFrom
OR target.To_Date != source.dtTo
OR target.BoxStatus != source.BoxStatus )
THEN UPDATE SET BoxNumber = source.BoxNum,
BoxTitle = source.BoxTitle,
BoxLocation = source.BoxLocation,
BoxSourceCode = source.BoxSourceCode,
BoxSource = source.BoxSource,
OSTNumber = source.OST,
FRCNumber = source.FRC,
WorkSite = source.WorkSite,
LoadedDate = source.dtLoaded,
TribeInfo = source.TribeInfo,
From_Date = source.dtFrom,
To_Date = source.dtTo,
BoxStatus = source.BoxStatus
WHEN NOT MATCHED THEN
INSERT (BoxID,BoxNumber,BoxTitle,BoxLocation,
BoxSourceCode,BoxSource,OSTNumber,FRCNumber,
WorkSite,LoadedDate,TribeInfo,From_Date,To_Date, BoxStatus)
VALUES (source.BoxID,source.BoxNum,source.BoxTitle,source.BoxLocation,
source.BoxSourceCode,source.BoxSource,source.OST,source.FRC,
source.WorkSite,source.dtLoaded,source.TribeInfo,source.dtFrom,source.dtTo, BoxStatus)
WHEN NOT MATCHED BY SOURCE THEN
DELETE;
--OUTPUT deleted.*, $action, inserted.*, GETDATE() INTO BISS_Historical..LogTblBoxInfo;
SELECT @@ROWCOUNT