• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

what is the correct syntax to change the follwing code to insert only new records using where not exists

Select M.Booked, Sum(M.Moved) as Qty,
  (Select Sum(Booked) From Moves Where Moves.Booked <= M.Booked) as Res
From Moves as M
Group by M.booked
order by M.Booked
0
ulsterweavers
Asked:
ulsterweavers
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what is the key to determine the "exists" ?
what is the database type?
0
 
ulsterweaversAuthor Commented:
Booked is the key (which is the string of a date, when booked), for example, if it has allready aggregated a certain amount of records, only new ones that have been added need to be inserted.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
so, you mean:
insert into xxxx
 
Select M.Booked, Sum(M.Moved) as Qty
, (Select Sum(Moves.Moved) From Moves Where Moves.Booked <= M.Booked) as Res
From Moves as M
where M.booked > ( SELECT MAX(xxx.booked) FROM xxx )
Group by M.booked
order by M.Booked

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now