存储过程:更新

时间:2017-05-30 09:28:20

标签: sql sql-server database stored-procedures

我是存储过程的新手,这是我的问题:

我想创建一个存储过程来更新表“F_COMPTET”

中的行

这是我的代码:

Create Procedure [dbo].[UpdateClt]
        @CT_Intitule    varchar(35),
        @CT_Contact     varchar(35),
        @CT_Adresse     varchar(35),
        @CT_Complement  varchar(35),
        @CT_CodePostal  varchar(35),
        @CT_Ville       varchar(35),
        @CT_CodeRegion  varchar(25),
        @CT_Pays        varchar(35),
        @N_Devise       smallint,
        @CT_Identifiant varchar(25),
        @CT_Siret       varchar(15),
        @N_CatCompta    smallint,
        @CT_Telephone   varchar(21),
        @CT_Telecopie   varchar(21),
        @CT_Email       varchar(69),
        @CT_Site        varchar(69),

    AS
    UPDATE [dbo].[F_COMPTET]
    SET

    [CT_Intitule]       = @CT_Intitule,
    [CT_Contact]        = @CT_Contact,
    [CT_Adresse]        = @CT_Adresse,
    [CT_Complement]     = @CT_Complement,
    [CT_CodePostal]     = @CT_CodePostal,
    [CT_Ville]          = @CT_Ville, 
    [CT_CodeRegion]     = @CT_CodeRegion,
    [CT_Pays]           = @CT_Pays, 
    [N_Devise]          = @N_Devise,
    [CT_Identifiant]    = @CT_Identifiant,
    [CT_Siret]          = @CT_Siret,
    [N_CatCompta]       = @N_CatCompta,
    [CT_Telephone]      = @CT_Telephone,
    [CT_Telecopie]      = @CT_Telecopie,
    [CT_Email]          = @CT_Email, 
    [CT_Site]           = @CT_Site, 


Where       [CT_Num] = @CT_Num,

这就是我遇到的问题:

Msg 156, Niveau 15, État 1, Procédure UpdateClt, Ligne 20
Syntaxe incorrecte vers le mot clé 'AS'.
Msg 156, Niveau 15, État 1, Procédure UpdateClt, Ligne 43
Syntaxe incorrecte vers le mot clé 'Where'.

您认为问题是什么?

2 个答案:

答案 0 :(得分:3)

删除最后一行逗号和WHERE子句逗号:

编辑:删除最后一个参数中的逗号

CREATE Procedure [dbo].[UpdateClt]
    @CT_Intitule    varchar(35),
    @CT_Contact     varchar(35),
    @CT_Adresse     varchar(35),
    @CT_Complement  varchar(35),
    @CT_CodePostal  varchar(35),
    @CT_Ville       varchar(35),
    @CT_CodeRegion  varchar(25),
    @CT_Pays        varchar(35),
    @N_Devise       smallint,
    @CT_Identifiant varchar(25),
    @CT_Siret       varchar(15),
    @N_CatCompta    smallint,
    @CT_Telephone   varchar(21),
    @CT_Telecopie   varchar(21),
    @CT_Email       varchar(69),
    @CT_Site        varchar(69)
AS
BEGIN 
 UPDATE [dbo].[F_COMPTET]
 SET
[CT_Intitule]       = @CT_Intitule,
[CT_Contact]        = @CT_Contact,
[CT_Adresse]        = @CT_Adresse,
[CT_Complement]     = @CT_Complement,
[CT_CodePostal]     = @CT_CodePostal,
[CT_Ville]          = @CT_Ville, 
[CT_CodeRegion]     = @CT_CodeRegion,
[CT_Pays]           = @CT_Pays, 
[N_Devise]          = @N_Devise,
[CT_Identifiant]    = @CT_Identifiant,
[CT_Siret]          = @CT_Siret,
[N_CatCompta]       = @N_CatCompta,
[CT_Telephone]      = @CT_Telephone,
[CT_Telecopie]      = @CT_Telecopie,
[CT_Email]          = @CT_Email, 
[CT_Site]           = @CT_Site
WHERE [CT_Num] = @CT_Num
END

答案 1 :(得分:0)

检查以下内容:

Create Procedure [dbo].[UpdateClt]
        @CT_Intitule    varchar(35),
        @CT_Contact     varchar(35),
        @CT_Adresse     varchar(35),
        @CT_Complement  varchar(35),
        @CT_CodePostal  varchar(35),
        @CT_Ville       varchar(35),
        @CT_CodeRegion  varchar(25),
        @CT_Pays        varchar(35),
        @N_Devise       smallint,
        @CT_Identifiant varchar(25),
        @CT_Siret       varchar(15),
        @N_CatCompta    smallint,
        @CT_Telephone   varchar(21),
        @CT_Telecopie   varchar(21),
        @CT_Email       varchar(69),
        @CT_Site        varchar(69),
       @CT_Num         VARCHAR(60)
    AS
    BEGIN
    UPDATE [dbo].[F_COMPTET]
    SET

    [CT_Intitule]       = @CT_Intitule,
    [CT_Contact]        = @CT_Contact,
    [CT_Adresse]        = @CT_Adresse,
    [CT_Complement]     = @CT_Complement,
    [CT_CodePostal]     = @CT_CodePostal,
    [CT_Ville]          = @CT_Ville, 
    [CT_CodeRegion]     = @CT_CodeRegion,
    [CT_Pays]           = @CT_Pays, 
    [N_Devise]          = @N_Devise,
    [CT_Identifiant]    = @CT_Identifiant,
    [CT_Siret]          = @CT_Siret,
    [N_CatCompta]       = @N_CatCompta,
    [CT_Telephone]      = @CT_Telephone,
    [CT_Telecopie]      = @CT_Telecopie,
    [CT_Email]          = @CT_Email, 
    [CT_Site]           = @CT_Site Where [CT_Num] = @CT_Num 

    END