I have loaded a table as follows by this SQL Query in QlikSense data load editor,
[RESOURCE_ALLOCATION]:
select t.rec_id as RESOURCE_ALLOC_TASKID,
t.name as RESOURCE_ALLOC_TASKNAME,
t.actual_starttime as RESOURCE_ALLOC_STARTTIME,
t.actual_endtime as RESOURCE_ALLOC_ENDTIME,
extract(year from t.actual_starttime) as RESOURCE_ALLOC_YEAR,
(t.actual_endtime - t.actual_starttime) as RESOURCE_ALLOC_DAYS,
t.resource_id as RESOURCE_ALLOC_ERSOURCEID,
r.name as RESOURCE_ALLOC_ERSOURCENAME
from public.dsh_project_tasks t, public.dsh_resources r
where t.resource_id = r.rec_id and extract(year from t.actual_starttime) = extract (year from t.actual_endtime);
Then I am tring to load another table by selecting from the last loaded table [RESOURCE_ALLOCATION] by another Query just after the one above in the load data editor , as follows
[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays,
if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS
from RESOURCE_ALLOCATION rr
group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;
[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
(365 - Sum(rr.RESOURCE_ALLOC_DAYS)) as busy_resourceDays,
if((365 - Sum(rr.RESOURCE_ALLOC_DAYS)) < 366, 'free', 'busy') as BUSY_RESOURCESTATUS
from resource_allocation rr
group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;
But I have an error in load data , saying
The following error occurred:
Invalid Path
The error occurred here:
[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays,
if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS
from RESOURCE_ALLOCATION rr group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR
Please help, why Do I get this error although same Query is selecting data well in DB console??
[Resource_Utilization]:
load rr.RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
rr.RESOURCE_ALLOC_YEAR as busy_resourceyear,
Sum(rr.RESOURCE_ALLOC_DAYS) as busy_resourceDays,
if(Sum(rr.RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free')as BUSY_RESOURCESTATUS
from RESOURCE_ALLOCATION rr
group by rr.RESOURCE_ALLOC_ERSOURCENAME, rr.RESOURCE_ALLOC_YEAR;
The SQL Syntax only works when the query is being passed to an SQL Server. When using the resulting tables you need to use the native Qlik Sense scripting language syntax. It's quite similar what you need to make your script work is this;
[Resource_Utilization]:
load RESOURCE_ALLOC_ERSOURCENAME as busy_resourcename,
RESOURCE_ALLOC_YEAR as busy_resourceyear,
Sum(RESOURCE_ALLOC_DAYS) as busy_resourceDays,
if(Sum(RESOURCE_ALLOC_DAYS) < 368, 'busy', 'free') as BUSY_RESOURCESTATUS
resident RESOURCE_ALLOCATION
group by RESOURCE_ALLOC_ERSOURCENAME, RESOURCE_ALLOC_YEAR;
The key change being changing the FROM to RESIDENT so the Sense knows to look inside it's own results tables not some external source for the table you reference. The rr. abbbreviations will cause it fail as Sense can only reference one table per script request.
Related
I'm executing a derivative function in TDengine database, and it reports an error.
My sql statement is:
select derivative(errors, 1s, 1) as errors from (select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s));
The error information is:
DB error: Invalid timeline function (0.002248s)
If I execute the following sql directly, it is ok.
select sum(errors) as errors from log.dnodes_info where ts>="2022-12-06 14:08:42" and ts < "2022-12-06 15:00:00" interval(1s) limit 10;
error information
Do I use it in a wrong way?
Is there a way I can dynamically inject the date in YYYYMMDD format into this PostgreSQL query that I am using with copy inside psql?
copy (SELECT
course.id, course.area, course.status, course.type,
customer.firstname, customer.lastname, customer.email
FROM course
JOIN customer_course
ON customer_course.course_id = course.id
JOIN customer
ON customer.id = customer_course.customer_id
WHERE course.type LIKE '%heathland%'
AND course.status = 'open'
) TO '~/Dropbox/CRMPicco/prod-customer-courses-' . (SELECT NOW()::date) . '.csv' WITH CSV;
When I run that query I get the following error:
ERROR: syntax error at or near "."
LINE 1: ...ace%' AND course.status = 'open' ) TO STDOUT . (SELECT ...
It would be advantageous if I could create this CSV with the current date without having to manually edit the query.
In psql you can set a variable to the name of the output file:
postgres=#> select '~/Dropbox/CRMPicco/prod-customer-courses-'||current_date||'.csv' as fname
postgres=#> \gset
postgres=#> copy (...) to :'fname';
Note the missing ; after the first select, you have to terminate that statement with \gset. The variable name is defined through the column alias of the "source".
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
I have following SQL query:
select * from P_SPC_LOT L,P_SPC_CHART_POINT CP
where L.spcs_id = CP.spcs_id and
(L.route like 'FL%' or L.route like 'RE%' or L.route like 'FE%') and
L.operation in ('123','234','456') and
L.data_collection_time > current_date -7 and rownum <100000
I am interesting to read L.operation values from external .csv file with "Operation" column. How that can be done? In addition, if reading from external file will slow query? I don't have DBA write privileges so looking for temporary csv table usage as not part of DB.
Import the CSV file into a table, and use it as follows (assuming the CSV file is loaded into a table named ops with a column named operations):
select *
from
P_SPC_LOT L
inner join P_SPC_CHART_POINT CP on L.spcs_id = CP.spcs_id
where
(L.route like 'FL%' or L.route like 'RE%' or L.route like 'FE%')
and L.operation in (select operation from ops)
and L.data_collection_time > current_date -7
and rownum <100000;
I am running a SQL query in stored procedure which is like following
SELECT
t1.id,t2.Name
FROM
table1 t1 , table2 t2 ,table2 t3,table4 t4
WHERE
t1.id=t3.t4.id
this query gets executed on SQL server 2008 when its compatible with SQL server 2000 but if we turn OFF the compatibility with SQL server 2000 then this Query gives syntax error which is expected.
Can some one help me to understand why this is happeneing ? thanks in advance
Original query:
SELECT
ConfigID , LocationDesc + '-' + LOBTeamDesc LocLOBTeamSource
FROM Config CONFIG , Location_LOBTeam LOCLOB , Location LOC , LOBTeam LOB, System SRC
WHERE CONFIG.LocationLOBTeamID = LOC.LOB.LocationLOBTeamID
AND CONFIG.SourceSystemID = SRC.SystemID
AND LOCLOB.LocationID = LOC.LocationID
AND LOCLOB.LOBTeamID = LOB.LOBTeamID
AND (GETDATE() BETWEEN CONFIG.effectiveDate AND CONFIG.EndDate
OR CONFIG.EndDate IS NULL)
ORDER BY
LOC.LocationCode
I think that original query, with current standard join syntax applied would be this:
SELECT
ConfigID
, LocationDesc + '-' + LOBTeamDesc LocLOBTeamSource
FROM Config CONFIG
INNER JOIN Location_LOBTeam LOCLOB
ON CONFIG.LocationLOBTeamID = LOCLOB.LocationLOBTeamID
INNER JOIN Location LOC
ON LOCLOB.LocationID = LOC.LocationID
INNER JOIN LOBTeam LOB
ON LOCLOB.LOBTeamID = LOB.LOBTeamID
INNER JOIN [System] SRC
ON CONFIG.SourceSystemID = SRC.SystemID
WHERE (GETDATE() BETWEEN CONFIG.effectiveDate AND CONFIG.EndDate
OR CONFIG.EndDate IS NULL)
ORDER BY
LOC.LocationCode
Perhaps this will help.
+EDIT
"System" as a table name, could that be a problem? Suggest you try it as [System]
+EDIT2
The original is given with this: LOC.LOB.LocationLOBTeamID but that appears to be an error as there is an alias LOCLOB
I think below post from msdn answers this issue Compatibility Levels and Stored Procedures
in the above post the point number 3 under section "Differences Between Compatibility Level 80 and Level 90" states "WHEN binding the column references in the ORDER BY list to the columns defined in the SELECT list, column ambiguities are ignored and column prefixes are sometimes ignored. This can cause the result set to return in an unexpected order."
on my database I am using compatibility level 80 i.e 2000 thats why it runs smoothly with the given syntax but when I remove this compatibility and make it to 100 i.e. 2008/R2 script gives syntax error which is expected