Results 1 to 4 of 4

Thread: update record with summ

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    update record with summ

    table SOMME

    AG DATA DIFF MASTRO POSIZ DCI
    100 26/08/2014 10 20 10 111
    100 26/08/2014 20 10 20 111/8
    200 26/08/2014 10 20 10 111


    table CASSA (result before query)

    AG DATA DIFF MASTRO POSIZ
    100 26/08/2014 0 0 0
    200 26/08/2014 0 0 0

    table CASSA (result after query)

    AG DATA DIFF MASTRO POSIZ
    100 26/08/2014 30 30 30
    200 26/08/2014 10 20 10

    I need, with a Join AG and DATA, to update the table CASSA with a summ of DIFF, MASTRO, and POSIZ but only if in DCI of SOMME is present 1118 and 1119/8, how to with a sql?

    Tks.

    Note:
    in CASSA not possible duplicate AG and DATA
    in DCI of SOMME i can have only two vlue 1118 or 1119/8
    Last edited by luca90; Sep 1st, 2014 at 02:27 AM.

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: update record with summ

    maybe something like this:
    Code:
    update cassa
    set diff=sumdiff,mastro=summastro,posiz=sumposiz
    from cassa inner join ( 
    	select ag,data,sum(diff) sumdiff,sum(mastro) summastro,sum(posiz) sumposiz
    	from somme
    	where not dci is null
    	group by ag,data
    ) T1 on T1.ag=cassa.ag and T1.data=cassa.data
    totally untested

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: update record with summ

    TKS...but syntiax error

  4. #4
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: update record with summ

    Quote Originally Posted by luca90 View Post
    TKS...but syntiax error
    1. What database system are you using?
    2. What is the error message?
    3. What have you tried to fix it?

    Please answer all three questions to get help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width