Skip to main content

Hello all! Relatively newbie here.

I think my question is simple but I am just struggling with finding a query for it.

 

I have a table in an SDE. An example of the structure:

object_id        job_id          update_start                               status

1                     xxx              2/15/2024 13:00:00                  Success

2                     xxx              2/20/2024 13:00:00                  Success

3                     xxx              2/25/2024 13:00:00                  Fail

 

I am using a FeatureReader to read this table and I need to extract the most recent succesful run from this table (i.e. in this case only row 2). I am using the where clause but it keeps returning me blank and I ran out of ideas.

 

Any help is appreciated!

Regards,

One way would be to remove the where clause and just add a StatisticsCalculator to the FeatureReader and select the attribute you want the max value for.  You have to read the entire dataset first to do this so keep that in mind.  

Using a where clause just filters rows - you can’t use an aggregate function like max in it.

SQLExecutor isn’t really a good option either since you’re reading from an SDE.

 

Good luck!


Hi, try this one: “update_start” = (SELECT MAX(“update_start”) FROM “database”.“table_name” WHERE “status” = ‘Success’)

I wasn't aware that this was possible, this post made me try it. 


Hi, try this one: “status” = ‘Success’ AND “update_start” = (SELECT MAX(“update_start”) FROM “database”.“table_name”)

I wasn't aware that this was possible, this post made me try it. 

 

This one didnt work but made me try a modification of it. The modified version worked:
update_start = (select max(update_start) from database.table where status = 'Success')

Thank you for the ideas!


This one didnt work but made me try a modification of it. The modified version worked:
update_start = (select max(update_start) from database.table where status = 'Success')

Thank you for the ideas!

Hehe yes I noticed my mistake, I have edited my reply but I was too slow it seems. Glad it worked out!


I just tried this too on my dataset and was able to get it work!  Very cool.  I get all the records that have the max value but that’s fine.

One HUGE thing to note is if you are querying against an SDE database (in my case with a MS SQL backend) make sure you are querying the correct table or view (in the WHERE clause in the FeatureReader)!

For example, if you have a feature class that has versioning enabled, use the _evw instead of the base table.  


Reply