简体   繁体   English

我在SQL Server 2008中使用JOB执行存储过程时失败了,但是没有很好的工作

[英]My stored procedure in SQL Server 2008 when is execute with JOB its fails, but without its working great

I have this stored procedure wich its like this : 我有一个这样的存储过程:

ALTER PROCEDURE [dbo].[P_ALIMENTATION_VolumeVentes]
AS
BEGIN

    SELECT EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, SecteurNomEDS,DirectionEDS,DirectionNomEDS,
            (SELECT count(*) FROM CPListeVentesNonConformes WHERE CPListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='PP') AS ListeVenteNC_PP,
             (SELECT count(*) FROM CEListeVentesNonConformes WHERE CEListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='ET') AS ListeVenteNC_ET,
             (SELECT count(*) FROM CPListeVentesNonConformes WHERE CPListeVentesNonConformes.EDS = CPRT.EDS AND TypePart='PP' OR TypePart='ET') AS ListeVenteNC_PPET,
            (SELECT count(*) FROM  ListeVentes WHERE IDES01 = CPRT.EDS AND TypePart='PP') AS ListeVentes
    INTO VolumeVentes
    FROM CPR CPRT
    GROUP BY EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, SecteurNomEDS,DirectionEDS,DirectionNomEDS,TypePart

END

When i execute with the command line EXEC [dbo].[P_ALIMENTATION_VolumeVentes] that work super great my table is create. 当我使用命令行EXEC [dbo]。[P_ALIMENTATION_VolumeVentes]执行该命令时,将创建我的表。

But when i use SQL Agent to schedule a job i have a nice surprise to have this error : 但是,当我使用SQL Agent安排工作时,我很惊讶地收到此错误:

Executed as user: ZRES\\CSAPREP10IUCRADM. 以用户身份执行:ZRES \\ CSAPREP10IUCRADM。 The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. 从varchar数据类型到datetime数据类型的转换导致值超出范围。 [SQLSTATE 22007] (Error 242) The statement has been terminated. [SQLSTATE 22007](错误242)该语句已终止。 [SQLSTATE 01000] (Error 3621). [SQLSTATE 01000](错误3621)。 The step failed. 该步骤失败。

The structure table who will be create VolumetVentes have no fields with a type as datetime 将要创建VolumetVentes的结构表没有类型为datetime的字段

Here is the structure of the table VolumeVentes 这是表VolumeVentes的结构

I don't understand exactly where is the error ? 我不明白错误在哪里?

Thank you for help 谢谢你的帮助

Actually it should never work since you already have VolumeVente table. 实际上,由于您已经具有VolumeVente表,因此它永远不会起作用。

SELECT INTO creates new table with columns described in select statement https://msdn.microsoft.com/en-us/library/ms188029(v=sql.120).aspx SELECT INTO使用选择语句https://msdn.microsoft.com/zh-cn/library/ms188029(v=sql.120).aspx中描述的列创建新表

You should modify this code to become INSERT SELECT . 您应该将此代码修改为INSERT SELECT

But you will probably still get the same conversion error because (I guess) column order is not correct in select statment and does not match column order in existing table. 但是您可能仍然会遇到相同的转换错误,因为(我猜)选择语句中的列顺序不正确,并且与现有表中的列顺序不匹配。 That is why you should always explicitly define column list in INSERT INTO clause, so the final script will look like: 这就是为什么您应该始终在INSERT INTO子句中显式定义列列表的原因,因此最终脚本应如下所示:

INSERT INTO VolumeVentes(EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS, ...)
SELECT EDS, NomEDS,AgenceEDS, AgenceNomEDS,SecteurEDS
FROM ...

Use 采用

INSERT INTO... Statement

instead of 代替

SELECT INTO FROM... Statement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM