I'm trying to create an email trigger in Google Sheets that will send me an email anytime the Price Fair Value Ratio for any stock is less than 1 (meaning the stock is undervalued). The Ratio is in column 6 and I pull in other corresponding columns into the email that is sent. However, when I set it up the trigger to run on edit, it does not send the intended emails. Any help would be great, thanks!
function FairValueNotification(e) {
var r = e.range;
var s = r.getSheet();
var ss = e.source;
var sName = s.getSheetName();
if(sName != "Brokerage" || r.getColumn() != 6) return;
//Price Fair Value Ratio
var value = e.value;
//Target Number of Shares
var value6 = s.getRange(r.getRow(), 13).getValue();
//Current Number of Shares
var value7 = s.getRange(r.getRow(), 12).getValue();
//Number of Shares to Buy
var value8 = value6 - value7
if(value > 1) return;
if(value7 > value6) return;
//Stock Name
var value2 = s.getRange(r.getRow(), 1).getValue();
//Stock Current Price
var value3 = s.getRange(r.getRow(), 9).getValue();
//Price Fair Value $
var value4 = s.getRange(r.getRow(), 5).getValue();
//Stock Ticker
var value5 = s.getRange(r.getRow(), 2).getValue();
value = value.toString();
var email = Session.getActiveUser().getEmail();
GmailApp.sendEmail("EMAIL", 'STOCK PRICE ALERT: ' + value2 + ' (' + value5 + ') - Brokerage', 'The following stock is currently undervalued:' + '\n\n' + 'Stock: ' + value2 + '\n' + 'Ticker: ' + value5 + '\n' + 'Current Price: $' + value3 + '\n' + 'Stock Fair Value: $' + value4 + '\n' + 'Stock Value Ratio: ' + value + '\n\n' + 'You should buy ' + value8 + ' shares.' + '\n' + 'You currently own ' + value7 + ' shares and have a target of ' + value6 + ' shares.');
}
Related
Given a table that looks like this:
id task scheduled_date reminder
-- ----------------------- ---------------- --------
1 mail january newsletter 2022-01-01 15 days
I had planned on executing a query to mimic date addition as in
SELECT TASK, SCHEDULED_DATE + 15 DAYS FROM ...
==> 2022-01-16
Unfortunately, using the REMINDER field gives an error:
SELECT TASK, (SCHEDULED_DATE + REMINDER) FROM ...
==>[Code: -182, SQL State: 42816] [SQL0182] A date, time, or timestamp expression not valid.
Is there any way to accomplish using the reminder field as a labeled duration? (I'm using IBMi DB2)
You'll need to convert the string "15 days" into an actual duration.
A date durration is a decimal(8,0) number representing YYYYMMDD
So 15 days would be 00000015
1 year, 00010000
1 year 1 month, one day '00010101`
create table testdur (
datedur decimal(8,0)
);
insert into testdur
values (15), (10000), (10101), (90), (300);
select current_date as curDate
, dateDur
,current_date + dateDur
from testdur;
Results
There is an attempt to implement the interval function available in Db2 for LUW. It supports string expression as a parameter, not just string constant as the built-in one.
The result of this function can participate in whatever allowed date arithmetic.
This works on Db2 for LUW v11.1+ and Db2 for IBM i v7.5+ at least.
create or replace function interval_d (p_interval varchar (100))
returns dec (8)
contains sql
deterministic
no external action
begin atomic
declare v_sign dec (1) default 0;
declare v_pattern varchar (100) default '([+-]? *[0-9]+) *(\w+)';
declare v_y int default 0;
declare v_m int default 0;
declare v_d int default 0;
declare v_occ int default 1;
declare v_num int;
declare v_kind varchar (10);
l1: while 1=1 DO
set v_kind =
lower
(
regexp_substr
(
p_interval
, v_pattern
, 1, v_occ, '', 2
)
);
if v_kind is null then leave l1; end if;
set v_num =
int
(
replace
(
regexp_substr
(
p_interval
, v_pattern
, 1, v_occ, '', 1
)
, ' ', ''
)
);
if sign (v_num) * v_sign < 0 then
signal sqlstate '75001' set message_text = 'Sign of all operands must be the same';
end if;
if v_sign = 0 then set v_sign = sign (v_num); end if;
if v_kind in ('d', 'day', 'days')
then set v_d = v_d + v_num;
elseif v_kind in ('mon', 'mons', 'month', 'months')
then set v_m = v_m + v_num;
elseif v_kind in ('y', 'year', 'years')
then set v_y = v_y + v_num;
else
signal sqlstate '75000' set message_text = 'wrong duration';
end if;
set v_occ = v_occ + 1;
end while l1;
if abs (v_d) > 99 then
set v_m = v_m + v_d / 30, v_d = mod (v_d, 30);
end if;
if abs (v_m) > 99 then
set v_y = v_y + v_m / 12, v_m = mod (v_m, 12);
end if;
return v_y * 10000 + v_m * 100 + v_d;
end
select interval_d (i) as d
from
(
values
('4 years 2 months 3 days')
, ('3 day 4 year 2 month')
, ('-4y -2mon -3d')
) t (i)
D
40203
40203
-40203
fiddle
I can't identify the syntax mistake on this query, where´s the syntax mistake?
SELECT A.WPAN8, A.WPSRP1, A.WPBP01, A.WPSLSM, A.WP55QTA1, A.WPCENTYR,
A.WPAAN01, A.WPAAN02, A.WPAAN03, A.WPAAN04, A.WPAAN05, A.WPAAN06,
A.WPAAN07, A.WPAAN08, A.WPAAN09, A.WPAAN10, A.WPAAN11, A.WPAAN12,
cast(((((((cast(cast(((WPUPMJ / 1000) + 1900) as decimal (4,0)) as
char(4)) || '-01-01 ') || substring(cast(cast((WPUPMT + 1000000) as
decimal (7,0)) as char(7)) from 2 for 2)) || ':') ||
substring(cast(cast((WPUPMT + 1000000) as decimal (7,0)) as char(7)) from
4 for 2)) || ':') || substring(cast(cast((WPUPMT + 1000000) as decimal
(7,0)) as char(7)) from 6 for 2)) as timestamp)+
ceiling(cast(substring(cast(cast(((WPUPMJ + 1900000) - 1) as decimal (7))
as character (7)) from 5 for 3) as decimal (3)))DAY as maxdate FROM
CRPDTA.F5742001 A where cast(((((((cast(cast(((WPUPMJ / 1000) + 1900) as
decimal (4,0)) as char(4)) || '-01-01 ') || substring(cast(cast((WPUPMT +
1000000) as decimal (7,0)) as char(7)) from 2 for 2)) || ':') ||
substring(cast(cast((WPUPMT + 1000000) as decimal (7,0)) as char(7)) from
4 for 2)) || ':') || substring(cast(cast((WPUPMT + 1000000) as decimal
(7,0)) as char(7)) from 6 for 2)) as timestamp)+
ceiling(cast(substring(cast(cast(((WPUPMJ + 1900000) - 1) as decimal (7))
as character (7)) from 5 for 3) as decimal (3)))DAY > '2000-01-01
00:00:00.000000';
It is saying ERROR: syntax error at or near "DAY"
postgresql uses a slightly different interval syntax to that.
I think you want * '1 day'::interval instead of DAY
I tried to get cumulative sums throught column week (and if is possible, then get result ordered by column Datum$ADTE) in my query:
select
A.Castka "Amount",
'Cashflow' as N,
A.Datum$DATE "Datum",
cast(A.Rok as varchar(4)) + '-' + cast(A.Tyden as varchar(4)) "Week"
from iGateCashflow A
where
1 = 1
and A.BusTransaction_ID = '1D00000101'
and A.Vyjasneno = 'A'
and cast(datepart(week ,convert(date, dbo.ib_DateToString(Napocteno$DATE, 'dd.mm.yyyy'), 104)) as varchar(4))
= 44
In where clause are conditions, whichs will be edited througt external form.
I would like to get result like this (better without Amount column)
week N Amount Result
44 Cashflow 150 150
45 Cashflow 200 350
46 Cashflow 300 650
47 Cashflow 350 1000
I tried something like this, but I can't achieve my expected result:
select
sum(y.Amount),
Y.N,
Y.Week
from (
select
A.Castka "Amount",
'Cashflow' as N,
A.Datum$DATE "Datum",
cast(A.Rok as varchar(4)) + '-' + cast(A.Tyden as varchar(4)) "Week"
from iGateCashflow A
where
1 = 1
and A.BusTransaction_ID = '1D00000101'
and A.Vyjasneno = 'A'
and cast(datepart(week ,convert(date, dbo.ib_DateToString(Napocteno$DATE, 'dd.mm.yyyy'), 104)) as varchar(4))
= 44
) X
join (
select
A.Castka "Amount",
'Cashflow' as N,
cast(A.Rok as varchar(4)) + '-' + cast(A.Tyden as varchar(4)) "Week"
from iGateCashflow A
where
1 = 1
and A.BusTransaction_ID = '1D00000101'
and A.Vyjasneno = 'A'
and cast(datepart(week ,convert(date, dbo.ib_DateToString(Napocteno$DATE, 'dd.mm.yyyy'), 104)) as varchar(4))
= 44
) Y on Y.Week <= X.Week
group by
Y.N,
Y.Week
order by
Y.Week
I think there's more your question than what you showed. But use this as an idea (you'll need to add in WHERE conditions, etc)
SELECT *,
SUM(Amount) OVER (ORDER BY [week])
FROM iGateCashflow
Better to use OVER Clause to get Sum partition by Week and order by Date, please refer to
Over Clause
Maybe try something like this
select
cast(A.Rok as varchar(4)) + '-' + cast(A.Tyden as varchar(4)) "Week",
sum(B.Castka) "Total amount"
from iGateCashflow A
inner join iGateCashflow B
on A.BusTransaction_ID = B.BusTransaction_ID
and A.Vyjasneno = B.Vyjasneno
and B.week <= A.week --> if week is a calculated field, include the calculation here for both 'week's
where
1 = 1
and A.BusTransaction_ID = '1D00000101'
and A.Vyjasneno = 'A'
and cast(datepart(week ,convert(date, dbo.ib_DateToString(Napocteno$DATE, 'dd.mm.yyyy'), 104)) as varchar(4))
= 44
group by cast(A.Rok as varchar(4)) + '-' + cast(A.Tyden as varchar(4)) "Week"
I am doing a sql server report that shows running daily, monthly, and yearly totals at the bottom of the report.
I figured out how to do the daily report by taking the datediff of the "timestamp" field and a getdate() and returning rows that were = 0. That way I knew the difference in dates was 0 days and thus part of the daily total.
I am running into an issue as to a good way to do this with month and year. Here is the query I have for month calculation and it is giving me way more results than it should (I have another table which i'm using to double check my calculations. I should get about 300 as my total but the query below gives me about 7400 instead. Just a little off)
SELECT SUM(Rc0) AS Good,
SUM(Rc0 + Rc1 + Rc2 + Rc3 + Rc4 + Rc5 + Rc6 + Rc7 + Rc8 + Rc9 + Rc10 + Rc11 + Rc12 + Rc13 + Rc14 + Rc15 + Rc16 + Rc17 + Rc18 + Rc19 + Rc20 + Rc21 + Rc22 + Rc23
+ Rc24 + Rc25 + Rc26 + Rc27 + Rc28 + Rc29 + Rc30 + Rc31 + Rc32 + Rc33 + Rc34 + Rc35 + Rc36 + Rc37 + Rc38 + Rc39 + Rc40) AS Not_Good
FROM someTable WHERE (MONTH(timestamp) = MONTH(GETDATE())) and (YEAR(timestamp) = YEAR(GETDATE()))
edit: alternate form of query that is giving me same result
SELECT SUM(Rc0) AS Good,
SUM(Rc0 + Rc1 + Rc2 + Rc3 + Rc4 + Rc5 + Rc6 + Rc7 + Rc8 + Rc9 + Rc10 + Rc11 + Rc12 + Rc13 + Rc14 + Rc15 + Rc16 + Rc17 + Rc18 + Rc19 + Rc20 + Rc21 + Rc22 + Rc23
+ Rc24 + Rc25 + Rc26 + Rc27 + Rc28 + Rc29 + Rc30 + Rc31 + Rc32 + Rc33 + Rc34 + Rc35 + Rc36 + Rc37 + Rc38 + Rc39 + Rc40) AS Not_Good
FROM someTable
WHERE convert(varchar(7), timestamp, 126) = convert(varchar(7), getdate(), 126)
--As a generic sort of grouping including most spans.....
SELECT
'Year' = DATEPART(Yy, rowdate),
'Month' = DATEPART(Mm, rowdate),
'Week' = DATEPART(wk, rowdate),
'Total' = sum(yournumericfield)
FROM sometable
GROUP BY
DATEPART(Yy, rowdate),
DATEPART(Mm, rowdate),
DATEPART(wk, rowdate)
ORDER BY
DATEPART(Yy, rowdate),
DATEPART(Mm, rowdate),
DATEPART(wk, rowdate)
Hi i have developed crystal report in asp.net web site
i want to set currency format like 1,20,000 (Indian Currency) but right now currency take My Server Hosted Currency Format and i was working for indian company so i there any format to convert currency in indian format for crystal report//
-- You can use below said code to your report part;
CStr({#FieldName}, "##,##,##,###.##")
And you are working for Indian Company, you will needed in words also. To write in words, use below said code;
numbervar RmVal:=0;
numbervar Amt:=0;
numbervar pAmt:=0;
stringvar InWords :="Rupees ";
Amt := {#FieldName} ;
if Amt > 10000000 then RmVal := truncate(Amt/10000000);
if Amt = 10000000 then RmVal := 1;
if RmVal = 1 then
InWords := InWords + " " + towords(RmVal,0) + " crore"
else
if RmVal > 1 then InWords := InWords + " " + towords(RmVal,0) + " crores";
Amt := Amt - Rmval * 10000000;
if Amt > 100000 then RmVal := truncate(Amt/100000);
if Amt = 100000 then RmVal := 1;
if RmVal = 1 then
InWords := InWords + " " + towords(RmVal,0) + " lakhs"
Else
If RmVal > 1 then InWords := InWords + " " + ToWords(RmVal,0) + " Lakhs";
Amt := Amt - Rmval * 100000;
if Amt > 0 then InWords := InWords + " " + towords(truncate(Amt),0);
pAmt := (Amt - truncate(Amt)) * 100;
if pAmt > 0 then
InWords := InWords + " and " + towords(pAmt,0) + " paisa only"
else
InWords := InWords + " only";
ProperCase(InWords)