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
182 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
  • 2
3 Comments
 
LVL 142

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 142

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updating a table from a temp table 4 36
SQL Pivot Rows To Columns 10 54
VB.net and sql server 4 36
Connection to multiple databases 13 19
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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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