QLIKVIEW 11: Formula works on Text Object but not in LOAD SCRIPT - qlikview

I have the following formula in a Text Object:
=Num(Sum(Aggr(Count({<Jahr={$(vTodayYear)}, Kw={">=1<=$(vTodayKw)"}, Database.Kennzahl={'Ew'}, Database.Szenario={'Actual'}>} DISTINCT Database.MitarbeiterID), Kw) / vTodayKw) , '###.##0')
This works and it gives me the desired Value. But when I want to SET it to LOAD SCRIPT like this:
SET vMyVar = =Num(Sum(Aggr(Count({<Jahr={$(vTodayYear)}, Kw={">=1<=$(vTodayKw)"}, Database.Kennzahl={'Ew'}, Database.Szenario={'Actual'}>} DISTINCT Database.MitarbeiterID), Kw) / vTodayKw) , '###.##0');
This doesn't work and theres no ErrorMessage :(
Thanks for any help!

there is no support for Set Analysis in a LOAD statement.
You have to rewrite your statement to use it in the LOAD statement.
Something like this (depending all fields are in a table named 'Database'):
tmp_Mitarbeiter_tbl:
LOAD Count (Distinct Database.MitarbeiterID) as tmp_Mitarbeiter_count
Resident Database
Where Jahr = $(vTodayYear)
and Kw >= 1 and Kw <= $(vTodayKw)
and Database.Kennzahl = 'Ew'
and Database.Szenario = 'Actual';
LET vMyVar = Peek('tmp_Mitarbeiter_count');
DROP Table tmp_Mitarbeiter_tbl;
Best regards,
Tom

Related

How to set variabel In Toad for oracle

How to Set variabel call in toad for orcale?
Like i have Query for input 3 report_dat, and 1 want create variable, so that i only input once
I have create like this
def report_date = 2;
def report_year = 2021;
and in where condition, i have set like this.
where H_CLOSING_PERIOD.BULAN = &report_date
and H_CLOSING_PERIOD.TAHUN = &report_year
But, when i run that query, it's still request input from user, like thisenter image description here
Try replacing with the following:
variable report_date H_CLOSING_PERIOD.BULAN%TYPE; --not sure of your data types, you can adjust these
variable report_year H_CLOSING_PERIOD.TAHUN%TYPE;
SELECT 2
, 2021
INTO :report_date
, :report_year
FROM dual;
and then when you use the binds:
WHERE H_CLOSING_PERIOD.BULAN = :report_date
AND H_CLOSING_PERIOD.TAHUN = :report_year
In TOAD, the simplest way (from my point of view), is to use bind variables. How? Simply precede their names with a colon sign:
where H_CLOSING_PERIOD.BULAN = :report_date
and H_CLOSING_PERIOD.TAHUN = :report_year
TOAD will prompt you to enter their values. For any subsequent execution, just hit ENTER (i.e. you don't have to enter their values, unless you want to).

How to write an Open SQL statement with substring in the JOIN ON condition? [duplicate]

I have the following select statement in ABAP:
SELECT munic~mandt VREFER BIS AB ZZELECDATE ZZCERTDATE CONSYEAR ZDIMO ZZONE_M ZZONE_T USAGE_M USAGE_T M2MC M2MT M2RET EXEMPTMCMT EXEMPRET CHARGEMCMT
INTO corresponding fields of table GT_INSTMUNIC_F
FROM ZCI00_INSTMUNIC AS MUNIC
INNER JOIN EVER AS EV on
MUNIC~POD = EV~VREFER(9).
"where EV~BSTATUS = '14' or EV~BSTATUS = '32'.
My problem with the above statement is that does not recognize the substring/offset operation on the 'ON' clause. If i remove the '(9) then
it recognizes the field, otherwise it gives error:
Field ev~refer is unknown. It is neither in one of the specified tables
nor defined by a "DATA" statement. I have also tried doing something similar in the 'Where' clause, receiving a similar error:
LOOP AT gt_instmunic.
clear wa_gt_instmunic_f.
wa_gt_instmunic_f-mandt = gt_instmunic-mandt.
wa_gt_instmunic_f-bis = gt_instmunic-bis.
wa_gt_instmunic_f-ab = gt_instmunic-ab.
wa_gt_instmunic_f-zzelecdate = gt_instmunic-zzelecdate.
wa_gt_instmunic_f-ZZCERTDATE = gt_instmunic-ZZCERTDATE.
wa_gt_instmunic_f-CONSYEAR = gt_instmunic-CONSYEAR.
wa_gt_instmunic_f-ZDIMO = gt_instmunic-ZDIMO.
wa_gt_instmunic_f-ZZONE_M = gt_instmunic-ZZONE_M.
wa_gt_instmunic_f-ZZONE_T = gt_instmunic-ZZONE_T.
wa_gt_instmunic_f-USAGE_M = gt_instmunic-USAGE_M.
wa_gt_instmunic_f-USAGE_T = gt_instmunic-USAGE_T.
temp_pod = gt_instmunic-pod.
SELECT vrefer
FROM ever
INTO wa_gt_instmunic_f-vrefer
WHERE ( vrefer(9) LIKE temp_pod ). " PROBLEM WITH SUBSTRING
"AND ( BSTATUS = '14' OR BSTATUS = '32' ).
ENDSELECT.
WRITE: / sy-dbcnt.
WRITE: / 'wa is: ', wa_gt_instmunic_f.
WRITE: / 'wa-ever is: ', wa_gt_instmunic_f-vrefer.
APPEND wa_gt_instmunic_f TO gt_instmunic_f.
WRITE: / wa_gt_instmunic_f-vrefer.
ENDLOOP.
itab_size = lines( gt_instmunic_f ).
WRITE: / 'Internal table populated with', itab_size, ' lines'.
The basic task i want to implement is to modify a specific field on one table,
pulling values from another. They have a common field ( pod = vrefer(9) ). Thanks in advance for your time.
If you are on a late enough NetWeaver version, it works on 7.51, you can use the OpenSQL function LEFT or SUBSTRING. Your query would look something like:
SELECT munic~mandt VREFER BIS AB ZZELECDATE ZZCERTDATE CONSYEAR ZDIMO ZZONE_M ZZONE_T USAGE_M USAGE_T M2MC M2MT M2RET EXEMPTMCMT EXEMPRET CHARGEMCMT
FROM ZCI00_INSTMUNIC AS MUNIC
INNER JOIN ever AS ev
ON MUNIC~POD EQ LEFT( EV~VREFER, 9 )
INTO corresponding fields of table GT_INSTMUNIC_F.
Note that the INTO clause needs to move to the end of the command as well.
field(9) is a subset operation that is processed by the ABAP environment and can not be translated into a database-level SQL statement (at least not at the moment, but I'd be surprised if it ever will be). Your best bet is either to select the datasets separately and merge them manually (if both are approximately equally large) or pre-select one and use a FAE/IN clause.
They have a common field ( pod = vrefer(9) )
This is a wrong assumption, because they both are not fields, but a field an other thing.
If you really need to do that task through SQL, I'll suggest you to check native SQL sentences like SUBSTRING and check if you can manage to use them within an EXEC_SQL or (better) the CL_SQL* classes.

How can I refer to 2 differents dataset into a gsheet query formula?

I'm trying to get a formula to match 2 different data set in google sheets.
I did the following but I keep getting "parse error"
iferror(if(len($D10)> 0,
query({'Sheet1'!$A$2:$T;'Sheet2'!$A$2:$BK}
"select {'Sheet2'!$A$2:$BK}.B where {'Sheet2'!$A$2:$BK}.A contains 'condition2'
and {'Sheet2'!$A$2:$BK}.D contains'"&$D$4&"
and {'Sheet1'!$A$2:$T}.N >= date '"&text(($A$4), "YYYY-MM-DD")&"'
and {'Sheet1'!$A$2:$T}.N <= date '"&text(($B$4), "YYYY-MM-DD")&"'",0),""),"")
With D10 is the cell that I'll look up the match for.
Let me know if you have any tips and thanks!
The syntax for QUERY is QUERY(data, query, [headers])
In your case, you forgot the , between the data and the query.
It should be ...query({'Sheet1'!$A$2:$T;'Sheet2'!$A$2:$BK}, "select {'Sheet2'!$A$2:$BK}.B where...

how to get a value from the results of another column calculation in same table

I tried to retrieve a value from the calculation of several columns,
in this case try to apply the formula "(a + (a / 25 * b)) - c" to be processed using sql language which I will use in codeigniter.
I also tried using "derived table" like SELECT .... FROM (SELECT... FROM...) AS dt
but I had difficulty when applying it to my case in codeigniter
private function _get_datatables_query(){
$intvl = '2';
$tgl_stok = '2019-09-30';
$this->db->SELECT('p.hso, p.no_part, p.nama_part, jml, sp.oh, sum(p.qty)+(sum(p.qty)/25*$intvl)-sp.oh as suggest');
$this->db->FROM('penjualan p');
$this->db->JOIN('stok_part sp', 'sp.no_part = p.no_part', 'left');
$this->db->WHERE("sp.tgl = '$tgl_stok' AND p.tgl BETWEEN DATE_SUB('$tgl_stok', INTERVAL $intvl DAY) AND '$tgl_stok'");
$this->db->GROUP_BY('p.no_part');
//...other code...
}
I want a column with the alias suggest in the code to produce a calculated value of several other columns
I know writing code that I created is not in accordance with the rules of writing SQL, I tried a number of ways but it did not work. I am very grateful for your help
Instead of var you should use parameter in this way you can easly pass the value you need and avoid sqlinjection eg:
$sql = "SELECT p.hso, p.no_part, p.nama_part, jml, sp.oh, sum(p.qty)+(sum(p.qty)/25*?)-sp.oh as suggest
FROM enjualan p
LEFT JOIN stok_part sp ON sp.no_part = p.no_part
WHERE sp.tgl = ? AND p.tgl BETWEEN DATE_SUB(?, INTERVAL ? DAY) AND ?
GROUP BY p.no_part";
$this->db->query($sql, array($intval,$tgl_stok, $tgl_stok, $intvl, tgl_stok ));
}
I was solved this case.
the problem is in my query:
$this->db->SELECT('p.hso, p.no_part, p.nama_part, jml, sp.oh, sum(p.qty)+(sum(p.qty)/25*$intvl)-sp.oh as suggest');
and replace it with
$this->db->SELECT("p.hso, p.no_part, p.nama_part, sum(p.qty) as jml, sp.oh, sum(p.qty)+(sum(p.qty)/25*'$intvl')-sp.oh as s_po");
my mistake was writing quotation marks in the query

Update a Table using a Join

I wish to update a table using, but need to use another table to get the correct field. The new information is not taken from another field from another table.
The following SQL statement returns the correct information:
SELECT PURCHASEHEADER.ORDERNOTES
FROM PURCHASEHEADER, ASSEMBLYLINESOURCE
WHERE ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001
AND PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER
I have tried the following:
UPDATE PURCHASEHEADER SET PURCHASEHEADER.ORDERNOTES = 'Updated'
WHERE EXISTS (
SELECT 1 FROM ASSEMBLYLINESOURCE
WHERE PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER
) AND ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001
An error is returned saying: " ...Column Unknown ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID..." but it does exist as it works in the first query.
I have seen similar posts from Mark Rotteveel dated July 2017, but still can't get it to work.
There is an issue with your closing bracket. Try this, it worked for me.
UPDATE PURCHASEHEADER set PURCHASEHEADER.ORDERNOTES = 'Updated'
WHERE EXISTS (SELECT 1 FROM ASSEMBLYLINESOURCE WHERE
PURCHASEHEADER.ORDERNUMBER = ASSEMBLYLINESOURCE.PURCHASEORDERNUMBER AND
ASSEMBLYLINESOURCE.HEADERSYSUNIQUEID = 72637001)