Home » SQL & PL/SQL » SQL & PL/SQL » compare columns in two tables and trigger something when the condn fails
compare columns in two tables and trigger something when the condn fails [message #638138] Thu, 04 June 2015 02:05 Go to next message
kiranrathodkr916
Messages: 36
Registered: March 2014
Location: India
Member
I have two tables t1,t2

Table T1

period_date         unit
6/30/2015          55948
7/31/2015          33965
8/31/2015          83885
9/30/2015          79517
10/31/2015         63555
11/30/2015         33104
12/31/2015         72265
1/31/2016          16658


Table T2

volume             end_date
25118            1/31/2015
67628            2/28/2015
70801            3/31/2015
36159            4/30/2015
67126            5/31/2015
55948            6/30/2015
33965           7/31/2015
83885           8/31/2015
79517           9/30/2015
63555           10/31/2015
33104           11/30/2015
72265           12/31/2015
14658           1/31/2016
52986           2/29/2016


"I want to check all the future months(upcoming months-July,August,Sept etc) totals are matching from these two tables t1,t2.If it doesnt match then trigger email( pls ignore email part ,it is already done)"

I have done something like below

SELECT SUM (unit), b.volume ,period_date ,case when SUM (unit)=b.volume then 'true' else 'false' end status
FROM t1 a , t2 b
where period_date > to_date(to_char(sysdate,'Month'),'Month')
and A.period_date=B.end_date
GROUP BY period_date,b.volume
order by 2;



Is this right?If yes how do I do check this If it doesn't match then trigger email

future months are 7/31/2015,8/31/2015,9/30/2015,10/31/2015,11/30/2015,12/31/2015,1/31/2016,2/29/20‌​16.I am not sure how to check this condn"if totals doesnt match then trigger email

my question is "I want to check the condn,if the totals doesnt match then trigger" how can i do that in code?can anyone help me

compare total is matching for future months
if anything is different then trigger

[Updated on: Thu, 04 June 2015 02:33]

Report message to a moderator

Re: compare columns in two tables and trigger something when the condn fails [message #638141 is a reply to message #638138] Thu, 04 June 2015 03:47 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
Please provide the create and insert statements. And show your desired output. See how to post a test case.
Previous Topic: Create dummy records using Model clause with condition for date field
Next Topic: Show the total of records with last record
Goto Forum:
  


Current Time: Tue Mar 19 04:41:13 CDT 2024