IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage SQL Discussion :

Update d'un champ obtenu par sous-requête


Sujet :

Langage SQL

  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2008
    Messages : 611
    Points : 359
    Points
    359
    Par défaut Update d'un champ obtenu par sous-requête
    Bonjour,

    Je travaille sous Oracle 10g. Je cherche à mettre à jour le prix d'inventaire pour les articles correspondant à "un certain type".

    Voici ma requête pour obtenir ce prix:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    select a.id_article, z.cout_total
    from toppdm.object o 
    inner join (select tmp.id_routing, sum(tmp.cout_pour_un) as cout_total
    from
    ((select b1.*
      from V_TRT_UNIT_BESOIN_ACHAT b1
     union
     select b2.*
     from V_TRT_UNIT_CDE_BES_ACHAT b2
     union 
     select b3.*
     from V_TRT_UNIT_BES_CDE_ACHAT b3
     union
     select b4.*
     from V_TRT_UNITTOT_BESOIN_ACHAT b4
     union 
     select b5.*
     from V_TRT_UNITTOT_BESAB1_ACHAT b5
     union
     select b6.*
     from V_TRT_UNITTOT_BESAB2_ACHAT b6
     union
     select b7.*
     from V_TRT_UNIT_TOLE_1 b7 
     union
     select b8.*
     from V_TRT_UNIT_TOLE_2 b8
     union
     select b9.*
     from V_TRT_UNIT_TOLE_3 b9 
     union
     select b10.*
     from V_TRT_UNIT_TOLE_4 b10
     union
     select b11.*
     from V_TRT_UNIT_TOLE_5 b11
     union 
     select b12.*
     from V_TRT_BES_M_MM b12
     union
     select b20.*
     from V_TRT_MAT_SANS_LIV b20
    ) tmp)
    group by tmp.id_routing) z
    on o.id_routing = z.id_routing 
    inner join toperp.t_article a
    on a.id_object = o.id_object
    where a.b_prod = -1
      and a.id_famille = 385
      and a.id_type_article = 1
      and o.type = 47
    Je souhaite mettre à jour le champ pu de la table t_article à partir de z.cout_total. L'identifiant est id_article.
    Je ne connais pas la syntaxe à adopter.

    Merci d'avance.
    Julien.

  2. #2
    Membre expérimenté
    Avatar de islamov2000
    Homme Profil pro
    Ingénieur d'études & developpement en informatique
    Inscrit en
    Septembre 2007
    Messages
    814
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Ingénieur d'études & developpement en informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2007
    Messages : 814
    Points : 1 717
    Points
    1 717
    Billets dans le blog
    6
    Par défaut
    en resumé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    UPDATE T_ARTICLE ART SET PU=(select cout_total from  ( ta_requete ) WHERE ART.id_article=ta_requete.id_article)
    en détail:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    UPDATE T_ARTICLE ART SET PU=(select cout_total from  ( --nouvelle ligne
    SELECT a.id_article, z.cout_total
    FROM toppdm.object o 
    INNER JOIN (SELECT tmp.id_routing, sum(tmp.cout_pour_un) AS cout_total
    FROM
    ((SELECT b1.*
      FROM V_TRT_UNIT_BESOIN_ACHAT b1
     union
     SELECT b2.*
     FROM V_TRT_UNIT_CDE_BES_ACHAT b2
     union 
     SELECT b3.*
     FROM V_TRT_UNIT_BES_CDE_ACHAT b3
     union
     SELECT b4.*
     FROM V_TRT_UNITTOT_BESOIN_ACHAT b4
     union 
     SELECT b5.*
     FROM V_TRT_UNITTOT_BESAB1_ACHAT b5
     union
     SELECT b6.*
     FROM V_TRT_UNITTOT_BESAB2_ACHAT b6
     union
     SELECT b7.*
     FROM V_TRT_UNIT_TOLE_1 b7 
     union
     SELECT b8.*
     FROM V_TRT_UNIT_TOLE_2 b8
     union
     SELECT b9.*
     FROM V_TRT_UNIT_TOLE_3 b9 
     union
     SELECT b10.*
     FROM V_TRT_UNIT_TOLE_4 b10
     union
     SELECT b11.*
     FROM V_TRT_UNIT_TOLE_5 b11
     union 
     SELECT b12.*
     FROM V_TRT_BES_M_MM b12
     union
     SELECT b20.*
     FROM V_TRT_MAT_SANS_LIV b20
    ) tmp)
    GROUP BY tmp.id_routing) z
    ON o.id_routing = z.id_routing 
    INNER JOIN toperp.t_article a
    ON a.id_object = o.id_object
    WHERE a.b_prod = -1
      AND a.id_famille = 385
      AND a.id_type_article = 1
      AND o.type = 47
     
      ) WHERE ART.id_article=ta_requete.id_article)--nouvelle ligne

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Novembre 2008
    Messages
    611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2008
    Messages : 611
    Points : 359
    Points
    359
    Par défaut
    Merci beaucoup.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [AC-2002] Limite d'affichage d'un champ mémo par une requête
    Par azertix dans le forum Requêtes et SQL.
    Réponses: 3
    Dernier message: 29/01/2010, 10h59
  2. Référence à un champ dans une sous-requête
    Par Gluckens dans le forum Langage SQL
    Réponses: 4
    Dernier message: 13/04/2009, 20h08
  3. Rafraîchir les champs text par une requête
    Par nounowa dans le forum JDBC
    Réponses: 2
    Dernier message: 18/07/2007, 12h14
  4. Sélection de tous les champs d'une sous-Requête que je redéfini
    Par electrosat03 dans le forum Requêtes et SQL.
    Réponses: 1
    Dernier message: 28/06/2007, 16h43
  5. Ramener plusieurs champs dans une sous requête...
    Par David.V dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 12/01/2005, 07h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo