我在 SQL 中遇到了一个非常奇怪的错误,我需要一些帮助。下面的代码创建了此报告所需的两个存储过程:
USE [ONDTTEST]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE ONDT_OPS_OTD_STEP1
AS
BEGIN
SET NOCOUNT ON;
/** Create Table **/
CREATE TABLE ONDT_OPS_OTD_SMARTVIEW
(
ID varchar(15) NOT NULL,
STATUS char(1) NOT NULL
);
/** Insert data into table **/
INSERT INTO [ONDT_OPS_OTD_SMARTVIEW]
SELECT [ID]
,[STATUS]
FROM [CUSTOMER_ORDER]
WHERE [STATUS] = 'H';
/** Update customer order table from H to R **/
UPDATE [CUSTOMER_ORDER]
SET [STATUS] = 'R'
WHERE [STATUS] = 'H';
END
GO
CREATE PROCEDURE ONDT_OPS_OTD_STEP2
AS
BEGIN
SET NOCOUNT ON;
/** Update records back to H **/
UPDATE [CUSTOMER_ORDER]
SET [STATUS] = 'H'
WHERE [ID] IN (SELECT [ID] FROM [ONDT_OPS_OTD_SMARTVIEW]);
/** Drop Table **/
DROP TABLE ONDT_OPS_OTD_SMARTVIEW;
END
GO
当我执行两个存储过程时,它成功运行,但是当我从计划的作业中调用存储过程时,它会产生以下错误:
Executed as user: admin. String or binary data would be truncated. [SQLSTATE 22001] (Error 8152) The statement has been terminated. [SQLSTATE 01000] (Error 3621). The step failed.
我运行了分析器,发现它在两个过程的 CUSTOMER_ORDER 表的更新步骤中都失败了。Status 列设置为 char(1),存储过程在从查询中调用时可以正常工作,但在从作业中调用时会失败。
谢谢