Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

count records

I have a requirement where if the table has no data then I should not run that specific job. Is there a component that I can use to check for number of records. Like if count(*) = 0 then end the job else complete the run.
Can somebody show me an example?
MASTER JOB
BEGIN->JOB1->JOB2->END
Below is a DEPTJOB
TABLE1->TMAP->TABLE1_DM
if there are no records in DEPT then I want to exit and run only JOB2
Labels (2)
9 Replies
alevy
Specialist
Specialist

You would have to read the number of rows using t<DB>Input (SELECT COUNT(*) FROM DEPT) passing the result to, say, tSetGlobalVar and then have an If trigger from t<DB>Input where you can test the globalMap variable created to see if it's >0 and so trigger JOB1.
_AnonymousUser
Specialist III
Specialist III
Author

I have 5 seaparate jobs that needs this count(*) check. Is there a way I can create one job that would take table name as input and return me record count ...instead of doing the same thing in each job.
select count(*) from &variablename -> tsetGlobalvar
alevy
Specialist
Specialist

Sure. Put that part into a job or joblet using a context variable for the table name.
_AnonymousUser
Specialist III
Specialist III
Author

I created joblet like
INPUT -> toracleinput->tsetglobavar->output
toracleinput - I gave query like this select count(*) as numofrecords from context.tablename
tsetglobavar - key numofrecords values row1.numofrecords

INSIDE JOB1
JOBLET ->run if ->TABLE1->TMAP->TABLE1_DM
where to provide the value for context.tablename
I am really not clear... can anyone provide a sample flow
alevy
Specialist
Specialist

Just define it as the default value for the context variable in your job...
_AnonymousUser
Specialist III
Specialist III
Author

context variable is read only inside the job where I dropped the joblet. Unable to reuse the joblet
joblet -runif records >1 -toracleinput -> tmap -toraclebulkoutputexec
Any ideas how to do this? I need to basically reuse the query
"select count(*) from "+ context.table_name
alevy
Specialist
Specialist

Each job that uses the joblet needs to have the context variable defined with the relevant table name as its value. I don't understand why you think it can't be re-used.
_AnonymousUser
Specialist III
Specialist III
Author

thanks, I got the joblet working along with context .

Inside the job I have
joblet -> output_1 -> tjavarow - if numRecordCount>0 -> tjava
- if numRecordCount==0->-> tjava

tjavarow
output_row.numRecordCount = input_row.numRecordCount;
run if has errors not sure how to provide the condition inside run if. appreciate ur help
Is there a way I can get run if directly from joblet?
alevy
Specialist
Specialist

Unfortunately, joblets do not yet support RunIf triggers directly so I would design it as follows:
joblet:
toracleinput -main-> tsetglobavar -if (Integer)globalMap.get("numrecordcount")>0-> tjava -onsubjobok-> trigger_output_1
-if (Integer)globalMap.get("numrecordcount")==0-> tjava -onsubjobok-> trigger_output_2
Note that the tjavas are empty; they are just place-holders for the if triggers.
job:
joblet -onsubjobok1-> tjava
-onsubjobok2-> tjava
The problem with your approach is that the if is referencing a variable "numRecordCount" that doesn't exist, you would have to use <rowname>.numRecordCount (the rowname being that from the joblet). There is also no need to define output_row.numRecordCount in tjavarow unless there is a flow from tjavarow.