Qlik Sense Syntax in Data Loader Script - qliksense

How it would be this query in Qlik Sense syntax in data loader script?
TABLA_UTIL:
SQL
SELECT "PERIODO", SUM(DEUDAFINAL) as "DEUDAFINAL"
FROM "DL_RG_ANALYTICS"."SH_PROVISION" PRO WHERE ORG='628'
GROUP BY PERIODO
concatenate
SQL
SELECT OL.PERIODO, SUM(ABIERTA/1000000)+ DEUDA/1000000
FROM "DL_RG_ANALYTICS"."SH_OTRAS_LINEAS" OL LEFT JOIN SH_SALDO_NO_IDEN_RUT PRO ON(OL.PERIODO=PRO.PERIODO)
WHERE ((ol.TIPO_DEUDA='TRASPASO' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='SAE' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='REPACTACIONES' AND ol.DEFINICION='SALDO')
OR (ol.TIPO_DEUDA='RENEGOCIADO' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='AVANCE_EFECTIVO' AND ol.DEFINICION='SALDO' ))
AND PRO.TipoTarjeta='ABIERTA'
GROUP BY OL.PERIODO, PRO.DEUDA
Any help is welcome, thanks.

Hy,
that's easy, so cheer up.
If all field names in each table are identical, Qlik Sense will set this to one immediately after the other. To make it unambiguous:
concatenate(table_name)
is a good idea.
Look at this:
qlik script guide concatenate
Here's your example:
LIB CONNECT TO 'your_database';
TABLA_UTIL:
Load *;
SQL
SELECT
"PERIODO",
SUM(DEUDAFINAL) as "DEUDAFINAL"
FROM
"DL_RG_ANALYTICS"."SH_PROVISION" PRO WHERE ORG='628'
GROUP BY PERIODO;
LIB CONNECT TO 'your_second_database'; // where necessary
concatenate(TABLA_UTIL) //all field names must be the same
Load *;
SQL
SELECT
OL.PERIODO as "PERIODO",
SUM(ABIERTA/1000000)+ DEUDA/1000000 as "DEUDAFINAL"
FROM
"DL_RG_ANALYTICS"."SH_OTRAS_LINEAS" OL LEFT JOIN SH_SALDO_NO_IDEN_RUT PRO ON(OL.PERIODO=PRO.PERIODO)
WHERE ((ol.TIPO_DEUDA='TRASPASO' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='SAE' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='REPACTACIONES' AND ol.DEFINICION='SALDO')
OR (ol.TIPO_DEUDA='RENEGOCIADO' AND ol.DEFINICION='SALDO' )
OR (ol.TIPO_DEUDA='AVANCE_EFECTIVO' AND ol.DEFINICION='SALDO' ))
AND PRO.TipoTarjeta='ABIERTA'
GROUP BY OL.PERIODO, PRO.DEUDA;
//done

Disagree with previous answer ,
Concatenate is used to concatenate tables with different fields names.
Concatenation of tables with identical set of fields is automatic and can be avoided with NOCONCATENATE keyword (before LOAD)

Related

Crystal Reports not putting a record on the page

I have a very odd error with a report. There is one record in the record set returned to the report that is not printing on the page. When I copy the SQL statement and run it directly in SQL Server Management Studio, the row is there so I know it isn't in the selection formula. That also tells me table/view linking is correct (although I double checked that as well). I have gone through all of the grouping levels and looked at suppression settings and group sorting. Essentially, I have exhausted all options that I can find that would be causing this record to be suppressed and can't find anywhere that it would be suppressed or hidden from view. I haven't seen this behavior ever in 22 years of working with Crystal.
Any ideas of what may be causing one record to be suppressed while all others around it are still visible? I'm on version 2013, support pack 4 (14.1.4.13274). I would prefer not to rebuild this report from scratch if I can avoid it but I'm very close to the edge on this one.
Query as requested:
SELECT "KENNEL"."KENNEL_NO", "KENNEL"."ANIMAL_ID", "KENNEL"."TAG_NO", "ANIMAL"."YEARS_OLD", "ANIMAL"."MONTHS_OLD", "ANIMAL"."ANIMAL_ID", "ANIMAL"."PRIMARY_BREED", "ANIMAL"."SECONDARY_BREED", "ANIMAL"."PRIMARY_COLOR", "ANIMAL"."SECONDARY_COLOR", "ANIMAL"."ANIMAL_TYPE", "KENNEL"."OUTCOME_DATE_NULL", "v_tx_feed_sheet"."visit_type", "v_tx_feed_sheet"."resolved_date", "v_tx_feed_sheet"."visit_date", "v_tx_feed_sheet"."CONDITION_TYPE", "v_tx_feed_sheet"."TREATMENT_DESC", "dfl_kennel_groupings"."Ani_Loc_Sub", "dfl_kennel_groupings"."Ani_Loc", "KENNEL"."OUTCOME_TYPE", "KENNEL"."OUTCOME_SUBTYPE", "KENNEL"."OUTCOME_DATE", "v_tx_feed_sheet"."CYCLE", "v_tx_feed_sheet"."MEDICATION", "v_tx_feed_sheet"."NUM_DAYS", "dfl_kennel_groupings"."Offsite_Knl", "KENNEL"."INTAKE_DATE", "KENNEL"."REASON", "ANIMAL"."age_now", "ANIMAL"."DOB"
FROM (("ANIMAL"."SYSADM"."KENNEL" "KENNEL" INNER JOIN "ANIMAL"."SYSADM"."dfl_kennel_groupings" "dfl_kennel_groupings" ON "KENNEL"."KENNEL_NO"="dfl_kennel_groupings"."Kennel_No") LEFT OUTER JOIN "ANIMAL"."SYSADM"."ANIMAL" "ANIMAL" ON "KENNEL"."ANIMAL_ID"="ANIMAL"."ANIMAL_ID") LEFT OUTER JOIN "ANIMAL"."SYSADM"."v_tx_feed_sheet" "v_tx_feed_sheet" ON "KENNEL"."ANIMAL_ID"="v_tx_feed_sheet"."ANIMAL_ID"
WHERE "ANIMAL"."ANIMAL_TYPE"='DOG' AND "KENNEL"."KENNEL_NO" NOT LIKE 'DHA%' AND NOT ("KENNEL"."KENNEL_NO"='HOME' OR "KENNEL"."KENNEL_NO"='LOST') AND "KENNEL"."KENNEL_NO" LIKE 'B%' AND "dfl_kennel_groupings"."Offsite_Knl"='N' AND (("KENNEL"."OUTCOME_DATE_NULL"='Y' AND ((("v_tx_feed_sheet"."resolved_date">={ts '1899-12-30 00:00:00'} AND "v_tx_feed_sheet"."resolved_date"<{ts '1899-12-30 00:00:00'})) OR ("v_tx_feed_sheet"."resolved_date" IS NULL ))) OR ("KENNEL"."OUTCOME_DATE_NULL"='Y' AND "ANIMAL"."YEARS_OLD"=0 AND "ANIMAL"."MONTHS_OLD"<=4) OR ("ANIMAL"."ANIMAL_TYPE"='DOG' AND "KENNEL"."OUTCOME_SUBTYPE" LIKE 'SURG%' AND ("KENNEL"."OUTCOME_DATE">={ts '2017-04-26 00:00:00'} AND "KENNEL"."OUTCOME_DATE"<{ts '2017-04-27 00:00:00'})) OR ("ANIMAL"."ANIMAL_TYPE"='DOG' AND "KENNEL"."OUTCOME_SUBTYPE" LIKE 'SURG%' AND ("KENNEL"."OUTCOME_DATE">={ts '2017-04-27 00:00:00'} AND "KENNEL"."OUTCOME_DATE"<{ts '2017-04-28 00:00:00'})) OR ("ANIMAL"."ANIMAL_TYPE"='DOG' AND ("KENNEL"."INTAKE_DATE">={ts '2017-04-27 00:00:00'} AND "KENNEL"."INTAKE_DATE"<{ts '2017-04-28 00:00:00'}))) AND NOT ("KENNEL"."REASON"='DOA' OR "KENNEL"."REASON"='EUTH' OR "KENNEL"."REASON"='EUTH BEHAV' OR "KENNEL"."REASON"='EUTH ILL' OR "KENNEL"."REASON"='EUTH OLD' OR "KENNEL"."REASON"='EUTH OTHER' OR "KENNEL"."REASON"='EUTH YOUNG')

how to use for each loop in Progress?

Basically i'm trying to do a simple join. I'm a beginner in progress and even if i'm reading always the same things... my problem still unresolved ! :'(
I'm using unixodbc to communicate with my base and this is working like a charm when i'm using simple command like : SELECT * from PUB."Art"
I understood I have to do something who looks like that to join 2 tables :
FOR EACH PUB."Art" WHERE (PUB."Art".IdArt = 16969) ,
EACH PUB."ArtDet" WHERE (PUB."ArtDet".IdArt = PUB."Art".IdArt)
END
But this only return me [ISQL]ERROR: Could not SQLPrepare
I then try to simplify the thing with :
for each PUB."Art": display PUB."Art".IdArt end.
I try to put colon (or not) after the for each loop, using point / comma etc... but I never use the right syntax apparently... or I'm missing a thing to execute this command !
Is anyone can advice me ?
Thx a lot !
You appear to mixing SQL and 4GL syntax.
"FOR EACH" is 4GL. The SQL equivalent is "SELECT".
(If you are using 4GL you do not need then "PUB" prefix and quoting table and field names will not work.)
To do a join with SQL (or the 4GL) use a "," between the table names. For SQL your syntax would look something like:
SELECT * from PUB."Art", PUB."ArtDet"
Gory details regarding WHERE clauses, SQL INNER & OUTER joins etc. can be found in the online documentation:
https://community.progress.com/community_groups/openedge_general/w/openedgegeneral/1329.openedge-product-documentation-overview
You will want to navigate to your specific release and then find the "SQL" guide.

Issue with the join expression in Access 2013

Given below is the sample of my code. When I tried to switch to the design view it gives me an error:
"Microsoft Access can't represent the join expression a.Course_name=b.Course_name in Design view".
When I searched this error on stackoverflow I found one post. According to the post the solution is given in this link (http://support.microsoft.com/kb/207868). According to this link, try to remove extra parenthesis (especially nested parenthesis) and problem will be resolved. However, in my query I don't have nested parenthesis. So I don't know how to fix it. Any help would be appreciated.
SELECT a.Course_name, COUNT(b.Student_code) AS [Total], Format(b.Retrieved_date,"mmmm yyyy") AS [Month]
FROM Course AS a LEFT JOIN (SELECT b.Course_name, b.Student_code, b.Retrieved_date FROM pending-enrolment AS b WHERE b.Retrieved_date BETWEEN [Forms]![ParameterForm]![txtBeginDate] AND [Forms]![ParameterForm]![txtEndDate]) b
ON a.Course_name=b.Course_name
GROUP BY a.Course_name, b.Retrieved_date
;
Try the following code (tested and works 100%):
SELECT Course.Course_name, Count(b.Student_code) AS CountOfStudent_code,
Format([b].[Retrieved_date],"mmmm yyyy") AS [Month]
FROM Course
LEFT JOIN
(
SELECT [pending-enrolment].Course_name, [pending-enrolment].Student_code,
[pending-enrolment].Retrieved_date
FROM [pending-enrolment]
WHERE ([pending-enrolment].Retrieved_date
Between [Forms]![ParameterForm]![txtBeginDate]
And [Forms]![ParameterForm]![txtEndDate])
) AS b ON Course.Course_name = b.Course_name
GROUP BY Course.Course_name, Format([b].[Retrieved_date],"mmmm yyyy");

Crystal Report Show Database query

I am a newbie at CR. I have a report that someone else created. When I use the Database -> 'Show SQL Query' command the WHERE clause has a bunch of names. How can I find out where this list of names is coming from?
SELECT "billing_tx_charge_detail_2004"."date_of_service", "billing_tx_charge_detail_2004"."v_SERVICE_CODE", "billing_tx_charge_detail_2004"."v_PROVIDER_NAME", "billing_tx_charge_detail_2004"."service_status_value", "billing_tx_charge_detail_2004"."v_client_name", "billing_tx_charge_detail_2004"."guarantor_liability", "billing_tx_charge_detail_2004"."CLAIM_NUMBER", "billing_tx_charge_detail_2004"."GUARANTOR_ID", "billing_tx_charge_detail_2004"."v_service_value", "billing_tx_charge_detail_2004"."PATID", "cw_patient_notes"."service_duration", "cw_patient_notes"."note_type_value"FROM "SYSTEM"."billing_tx_charge_detail_2004" "billing_tx_charge_detail_2004" LEFT OUTER JOIN "CWSAVPMLIVESYSTEM"."cw_patient_notes" "cw_patient_notes" ON ((("billing_tx_charge_detail_2004"."FACILITY"="cw_patient_notes"."FACILITY") AND ("billing_tx_charge_detail_2004"."PATID"="cw_patient_notes"."PATID")) AND ("billing_tx_charge_detail_2004"."EPISODE_NUMBER"="cw_patient_notes"."EPISODE_NUMBER")) AND ("billing_tx_charge_detail_2004"."JOIN_TO_TX_HISTORY"="cw_patient_notes"."JOIN_TO_TX_HISTORY")
WHERE ("billing_tx_charge_detail_2004"."date_of_service">={d '2009-07-01'}
AND "billing_tx_charge_detail_2004"."date_of_service"<={d '2009-07-31'}) AND
("billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='BARNHART,SCOTT' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='BINKER,BARB MSW LISW' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='BRETNAN,BAUNEEN' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='CROWN,DWAYNE BS NCAC-I LADAC'
OR "billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='COFFEE,RAMBA BA LADAC' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='DECODE,TENISE MC LMFT LADAC' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='GONSALEZ,MAREN' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='HITAN,TOM' OR
"billing_tx_charge_detail_2004"."v_PROVIDER_NAME"='KOTUE,SHEENA')
ORDER BY "billing_tx_charge_detail_2004"."v_SERVICE_CODE",
"billing_tx_charge_detail_2004"."date_of_service", "billing_tx_charge_detail_2004"."PATID"
It is found in the Report ->Select Expert command! Hooray!
I knew as soon as I posted the question I would find the answer :)
You've got some choices. It's either:
In the record selection formula (Report > Edit Selection Formula > Record)
Hard-coded in the "Show SQL Query" window (though not as likely)
In a parameter that was either saved with the report, or contains default values (even less likely)

Reusing ?'s on a DBI prepare

Is there a way to reuse the ?'s used on a DBI prepare statement. Consider the following code:
$sth=$dbh->prepare("INSERT INTO mytable(a,b,c) SELECT ?,B(?),C(?)");
$sth->execute($a,$a,$a);
It would be very nice to instead use something like this:
#I'm making this up as something I hope exists
$sth=$dbh->prepare("INSERT INTO mytable(a,b,c) SELECT ?,B(?:1),C(?:1)");
$sth->execute($a);
Notice that only one $a is passed to the execute instead of three. Is there a way to do this in real life?
It depends on your DBD. For example, using DBD::Pg with the $1 style of placeholders, or DBD::Oracle with named placeholders and bind_param, you can do exactly what you like. But using the general purpose ? style of placeholders that works DBI-wide, it's not possible.
If you use a library to generate your SQL statements for you, e.g. SQL::Abstract or a full-on ORM like DBIx::Class, you won't have to worry about things like that.
Alternatively you can do something similar with just a few lines of code:
my $sql = 'INSERT INTO ...blah blah... VALUES (' . (join(', ', ('?') x scalar(#insert_elements))) . ')';
#hobbs' answer is right -- default DBI placeholders can't do it. #Ether's answer is right -- a SQL abstraction can make this a non-issue.
However, typically one need only bind each distinct parameterized value once. In your example, using a scalar derived table makes the user-supplied value available by name to the rest of the query:
my $sth = $dbh->prepare(<<'__eosql');
INSERT INTO mytable(a,b,c)
SELECT x, B(x), C(x) FROM (SELECT ? AS x) subq
-- Subquery may vary from DB to DB:
-- "FROM (SELECT ? AS x FROM DUAL) subq"
-- "FROM (SELECT ? FROM rdb$database) subq(x)"
-- "FROM (VALUES (?)) subq(x)"
-- etc.
__eosql
for $v (#values) {
$sth->execute($v);
}
Usually this is incrementally more "wire efficient" than the alternative, since the user-supplied parameter is typically transmitted just once instead of N times.
You can set SQL variables in one SQL statement and then use that variable multiple times in the next query.
$dbh->do('set #reusable = ?', undef, $perl_var);
$dbh->select_arrayref('select * from table where cola = #reusable or colb = #reusable');
No duplicated variables and you still get the safety of parameterized queries.