Sending sql output to email body with conditional subject line
hi ,
i have written below piece of code to meet the requirement but i am stuck in the logic here.
the requirement are:
1) to send the sql out put to email body with proper formatting.
2) if count_matching = Yes then mail should triggered with the subject line as "load counts Match for 'yyyymmdd'
else
"warning : load_count mismatch for 'yyyymmdd'"
please provide any other alternate solution if any..
thanks in advance
=====================
=====================
Last edited by Corona688; 03-13-2017 at 03:44 PM..
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
What do you mean by 'proper formatting'? What are you expecting and what do you get? To get strict formatting of text you may have to surround it with <pre>formatted text</pre> tags or send the email as an attachment.
The use of more especially may add newlines you didn't want. Just
should be sufficient.
Or perhaps
(a rare useful use of cat on a single file).
...
...
2) if count_matching = Yes then mail should triggered with the subject line as "load counts Match for 'yyyymmdd' else
"warning : load_count mismatch for 'yyyymmdd'" ...
...
...
...
Few more questions:
1) About the part of your logic in blue, did you mean:
a) Send an email with subject line: "warning: load counts mismatch for yyyymmdd" and the report as the email body, or
b) Do not send an email and just print "warning: ..." to stdout?
2) Will the part of your query in red return only one record?
- If it returns 4 records and 2 of them have counts_matching = "Yes" and the other 2 have counts_matching = "No", then what should be the final value of counts_matching?
thanks for reply . please let me know if more info is required,
1) About the part of your logic in blue, did you mean:
a) Send an email with subject line: "warning: load counts mismatch for yyyymmdd" and the report as the email body, or
b) Do not send an email and just print "warning: ..." to stdout? --no
--> in either case we need to send the report as the email body with the subject based on the output.
2) Will the part of your query in red return only one record? -- no , more than one record is also possible.
- If it returns 4 records and 2 of them have counts_matching = "Yes" and the other 2 have counts_matching = "No", then what should be the final value of counts_matching?
--> in this case if all the counts_matching records = 'Yes' then subject line should be as "load counts Match for 'yyyymmdd' "
else if any of the counts_matching records = 'No' then subject line should be as ""warning : load_count mismatch for 'yyyymmdd'" but report should contain all the counts_matching records.
...
...
2) Will the part of your query in red return only one record? -- no , more than one record is also possible.
- If it returns 4 records and 2 of them have counts_matching = "Yes" and the other 2 have counts_matching = "No", then what should be the final value of counts_matching?
--> in this case if all the counts_matching records = 'Yes' then subject line should be as "load counts Match for 'yyyymmdd' "
else if any of the counts_matching records = 'No' then subject line should be as ""warning : load_count mismatch for 'yyyymmdd'" but report should contain all the counts_matching records.
So, in order to determine the appropriate mail subject, you want to find out if all records had counts matching or not.
The following query returns 1 if all records inserted today in table t1 have identical values for table_row_count and input_record_cnt.
If at least one record has different values, then the query returns 0.
Of course, I assume that all both these columns (table_row_count and input_record_cnt) have numeric datatype, integer values and are non-nullable.
If NULLs are involved, then things become complicated pretty quickly.
- If one value is NULL and the other is, say, 5 then is that a mismatch or do you want to exclude them from comparison altogether, since NULL means "absence of value"?
- If both values are NULLs then is that a match or a mismatch?
Oracle has a lot of quirks regarding NULLs and I've avoided them in my suggested query.
Once you have this query, you can spool its output to another file and then read the said file to determine your mail subject.
Here's the shell script.
Note that I am echoing the mail command instead of executing it since I cannot email from my system.
Hello experts!!
I am trying to send an email with message body and attachment.but i am getting any one like message body or attachment.
I tried below command:
(echo "subject:test";echo "MIME-Version: 1.0";echo "content-transfer-encoding:base 64";echo "content-type:txt;name=test.txt";cat... (2 Replies)
I am making use of the following code to display the results of my txt file in an email:
mail -s 'Count Validation Test Comparison Results' Ronit@XYZ.com < Count_Validation_Results_`date +%m%d%Y`.txt
Email Output:
----------Query 1 Count Validation Results--------
Source count is 4
Target... (7 Replies)
Hi
I have a script running in lunix machine which emails log file content to my outlook.
Here is the actual log file result:
Image-1
In-Master:25028
ReplicaDn Consumer Supplier Delay
dc=xxx,dc=com lmjker0110:12345 ... (4 Replies)
I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email.
spool table_update.html;
SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription';
spool off;
exit;
Please use code tags next time for your code and data.... (9 Replies)
Hi ,
I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body.
p_id src_system amount
1 A 100
2 B 200
3 C ... (3 Replies)
Hi,
Im having a bit of an issue with using the uuencode command and sending out an email.
My aim is to send an email out which has a body and also have attachments. Currently I can either get one or the other and not both on the same email.
uuencode... (4 Replies)
Hi
i have a script which executes daily through cron. The output of the script is appended to a log file everyday
It also emails me the output of the logfile as we have the mailx command in the script
The below is my requirement :
Normally When I get the email it sends the entire content... (3 Replies)
Hi
I want to able to attach a file to a email and send it with a body
the body of the email is within the "body" file, and the attachment in "atch"
if i send like below it will send the email correctly
/usr/sbin/sendmail me@you.com< body
And when i send the attachment alone... (3 Replies)
Hi,
We have been trying to send mail with attachment and it is going fine, but when we try to attach a text to the body of the email, we find that the mail is going fine with the body text but the attachment is not going through. We are using ksh.
The command that is successfull without the... (6 Replies)
I want to send email for every row comes out of following SQL statement
thank you for your help.
*****SQL STATEMENT******
Select SCUSER AS "USER IDS" , SCEUSER AS "LOCKED OUT" FROM SYS.7333.F98OWSEC;
*******OUPUT COMES LIKE THIS AND ONE EMAIL COMES AS PER SCRIPT BELOW******
******BUT... (4 Replies)