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 |
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-03-15 : 08:35:51
|
| Hello and thanks in advance for your help on this.I have two tables: f_aot and f_rev they both contain jobkey and AOT recordsSo f_aot:jobkey AOT--------------1 41002 50003 6000............1000 4250And f_rev:jobkey AOT--------------1 37002 42003 5400............1000 9250I need to establish the differences for each job:So I will have the following:differences:jobkey AOT--------------1 4002 8003 600............1000 -5000I have started off creating a temp table but cant get theexact format |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-03-15 : 08:47:31
|
| We'll only help you with your homework when you've shown some effort yourself. This query is really easy, so give it a try and post what you came up with and we can help you from there.JimEveryday I learn something that somebody else already knew |
 |
|
|
tariq2
Posting Yak Master
125 Posts |
Posted - 2011-03-15 : 12:23:55
|
| Hi,So the following should give me three rows for jobkey 4570391strow AOT for jobkey 4570392ndrow rev for jobkey 4570393rd row diff between rev and AOT for jobkey 457039A few points about this:1) The code'INSERT into #Data0,0,0,REV-aOT'does not function2) For each jobkey I want one row with AOt,Rev,diff3) I would like this extended for teh whole sample of jobkeysRegards CREATE TABLE #data (jobkey int, rev bigint,AOT bigint,revAOT bigint)INSERT into #Dataselect max(jobkey),SUM(rev),0,0from F_REVwhere JobKey = 457039 and LedgerKey = 10 AND PeriodKey >84 and PeriodKey <97INSERT into #Dataselect max(jobkey),0,SUM(revenue),0from F_AOTwhere JobKey = 457039 and LedgerKey = 20 AND PeriodKey >84 and PeriodKey <97INSERT into #Data0,0,0,REV-aOT |
 |
|
|
Ranjit.ileni
Posting Yak Master
183 Posts |
Posted - 2011-03-16 : 02:43:32
|
| select t1.jobkey,t1.AOT as table1AOT,t2.AOT as table2AOT,t1.AOT-t2.AOT as diffAOTfrom table1 t1 join table2 t2 on t1.jobkey=t2.jobkey--Ranjit |
 |
|
|
|
|
|
|
|