Page 1 of 1

Get record count as a User Variable

Posted: Wed Dec 17, 2014 12:54 pm
by syang@collaborative.com
Hi guys,

This is the requirement:
If table A's record count is 0, don't run job.

I am running Job_A, which loads data into Table_A. Job_B will load data from Table_A into Table_B by truncate and insert. If Table_A is empty, Table_B will be truncated and 0 records will be inserted.

I am trying to get the record count of Table_A and use it as a User Variable in a nested condition.
If count(*) of Table_A > 0 then run Job_B

Thanks guys.

Posted: Wed Dec 17, 2014 1:03 pm
by chulett
Simplest way? Use a Server job to get the count and store it in USERSTATUS then interrogate that to trigger the second job or not.

Posted: Wed Dec 17, 2014 2:06 pm
by syang@collaborative.com
Thanks for the info. I have not worked with any server jobs, as I'm very new to DataStage. How would I set the UserStatus to the count of a table? I've been looking on this forum, and read about using a transformer, but no real detail on how the mechanics of how this is done.

Posted: Wed Dec 17, 2014 3:22 pm
by chulett
It's been discussed quite a bit so there's a lot to wade through when you search for it. I've found a fairly representative example in this post. If that all gets too complicated, you could always simply write the count to a flat file and then use something to read it back into the sequence job... in UNIX you could cat the file while in Windows a type would do it. You could do that in a custom routine or straight up in an Execute Command stage. Many ways to skin this cat. :wink:

Posted: Wed Dec 17, 2014 8:01 pm
by syang@collaborative.com
Thanks Craig. I ended up writing a routine to get the Link count.

I used this: DSGetLinkInfo(handle, Stage_Name, Link_Name, DSJ.LINKROWCOUNT)

Thanks again.

Posted: Wed Dec 17, 2014 10:43 pm
by chulett
If you've just loaded it and can use the link row count from the load job, then that works. I was thinking you wanted to check a table and that a single count of the records in the table would be a way to go.

Posted: Thu Dec 18, 2014 10:00 am
by collabxchange
Originally, I wanted to do an actual count of Table_A on the database, but I'm limited on time. This routine can check if any records were inserted into Table_A daily. It's no where near perfect, but will get the job done.

Posted: Thu Dec 18, 2014 3:07 pm
by ray.wurlod
If you want it bad, you get it bad. :idea: