?
Solved

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

Posted on 2008-10-21
3
Medium Priority
?
204 Views
Last Modified: 2010-03-20
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
Comment
Question by:ulsterweavers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22765677
what is the key to determine the "exists" ?
what is the database type?
0
 

Author Comment

by:ulsterweavers
ID: 22765729
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22765737
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question