Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rwaldron
Posting Yak Master
131 Posts |
Posted - 2008-07-08 : 11:09:27
|
| Hi all,Hopefully this is a quicky.I want to run a query today into a table.Then Tomorrow I want to run the same query.I want to output any new records that have been added since yesterday.Whats the best way to go about this.Some sort of comparison query?eg: today I run select refnumber from tbldata into tblatomorrow I run select refnumber from tbledata where refnumber doesn't already exist in tbla ??Please help.Ray.. |
|
|
cyberjunkyks
Starting Member
2 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-08 : 13:43:23
|
It depends on how your incremental changes occur. If you have only inserts happening on main table you can use EXCEPT. however if your table has all actions like update,insert,delete happening then you want a procedure of this kind.CREATE PROC CaptureIncData@Date datetimeASINSERT INTO DestTableSELECT fieldsFROM SourceTable sLEFT JOIN DestnTable dON d.KeyCol=s.KeyColWHERE d.KeyCol IS NULLAND s.CreatedDate>@DateUPDATE dSET d.fields=s.fieldsFROM DestTable dINNER JOIN SourceTable sON d.KeyCol=s.KeyColWHERE s.createddate > @DateDELETE dFROM DestTable dLEFT JOIN SourceTable sON d.KeyCol=s.KeyColWHERE s.KeyCol IS NULLGO |
 |
|
|
|
|
|