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
200 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 125 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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