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
197 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL query and VBA 5 61
SQL Query Works in SQL 2008 & 2012 But Not SQL 2016 15 94
T-SQL: Only Wanting One Record 8 54
SQL - Aging Report - Display Months with no data 8 39
'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 …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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