request updated data from three tables

  • Hi community

    I am a beginner in sql and for several days I'm hanging on a query that gives me a hard line so I need your help.

    I want to change my request data from a command. here is the query in microsoft sql server 2008 r2 I made, but that unfortunately does not work:

    update commande c, contenir ct set c.numboncmd= 2,c.libcmd='barytech',ct.codart='M0005',c.datcmd='30/09/2014',ct.qtecmd=250 where c.codcmd=ct.codcmd

    here are my tables attached file:

    please help me

  • please somebody help me

  • Welcome to the forums romy. I would first suggest you look over this post on how to best ask questions on the forums. You'll find many people willing and able to help you, but your problem must be articulated well so the community knows how to answer your question.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    If you're looking for general syntax on update statements, you can check out the Microsoft documentation on the update statement here:

    http://msdn.microsoft.com/en-us/library/ms177523.aspx

    It's not possible to update two tables simultaneously, so you'll need to look at two separate update statements. Unless you want to update every row in the table, you'll also need a search predicate (aka a WHERE clause).

    Neither of these necessarily do exactly what you're intending, but they should serve as examples of valid update statements which you can tweak to your needs. The first is a single table update. Without specifying a where clause, such an update would set EVERY VALUE in the table equal to the values specified. The second still only updates one of the tables (ct, or "contenir") but enforces rows which have a matching key value in the other table (c or "commande"). Again, without a where clause, every value in ct will be updated.

    update commande

    set numboncmd = 2,

    libcmd = 'barytech',

    datcmd = '30/09/2014'

    --where codcmd = 1

    update ct

    set codart = 'M0005',

    qtecmd = 250

    from commande c

    inner join contenir ct

    on c.codcmd = ct.codcmd

    -- where c.codcmd = 1

    Executive Junior Cowboy Developer, Esq.[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply