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 |
|
Jim77
Constraint Violating Yak Guru
440 Posts |
Posted - 2006-11-15 : 19:01:11
|
Hello there GuysI have two tables one is a alerts tablewith the following schema:prodcode saledatestoreval costalertReasonand I have another one called the reduced tablewith the following schema:prodcodesaledatestorevalcostreason (whos value is ALWAYS RTC (Reduced to clear))Now this reduced table gets updated everyday and what I am trying to achieve is to get all records in the alerts table that dont have a joining saledate and prodcode and store to be moved to a seperate non reduced table for reporting purposes.This procedure must happen everyday as both tables get inserted into daily (from external dat sources) for that specific day around the same time.What I came up with was something like this but can forsee it becoming a resource lag as it has to delete all contents and re import the same again:DROP TABLE NoReducedSELECT a.date, a.prodcode, a.store, a.val, a.cost, a.errorINTO NoReduced FROM Alerts a LEFT OUTER JOIN Reduced r ON a.prodcode = r.prodcode AND a.saledate = r.saledate AND a.store = r.storeWHERE r.val is null or r.cost is null or r.reason is nullEveryday ther is approx 30 thousand records going into each of them but only for the current date the historic data remains consistant.Is there any better more effecient less redundant way to do this ? |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-15 : 21:15:16
|
| Can't you just query those tables - is there really a need for the extra table every day?If you do need the extra table, you could try truncating it instead of dropping it, and then using an INSERT ... SELECT to get the data. Other than that, if the rows are different every day and you really need a separate copy of them, there won't be a much better way to do it. |
 |
|
|
Jim77
Constraint Violating Yak Guru
440 Posts |
Posted - 2006-11-16 : 05:19:52
|
| Thanks SNCould you reccomend any indexing for this maybe to improve performance ? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-16 : 05:30:37
|
No need for three WHEREs. Just check for one of the columns in the JOIN binding.SELECT a.date, a.prodcode, a.store, a.val, a.cost, a.errorINTO NoReduced FROM Alerts aLEFT JOIN Reduced r ON a.prodcode = r.prodcode AND a.saledate = r.saledate AND a.store = r.storeWHERE r.prodcode is null Peter LarssonHelsingborg, Sweden |
 |
|
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-11-16 : 11:15:53
|
quote: Originally posted by Jim77 Thanks SNCould you reccomend any indexing for this maybe to improve performance ?
Have you run it through the index tuning wizard? Without seeing your data it's hard for me to say, but the obvious columns to be considering in each table are the three that you use in the join. |
 |
|
|
Jim77
Constraint Violating Yak Guru
440 Posts |
Posted - 2006-11-16 : 12:17:01
|
| thanks guys I have never used the tuning wizard but I think that will change.cheers again ! |
 |
|
|
|
|
|
|
|