Assign SQL Result to Parameter

You can use conditional branching with derived tables to have two branches of logic depending on a value is found or not. See the tutorial article on conditional branching here: EasyMorph | Conditional workflows

The "Export to database" action can insert a row into the table. You can use it in the workflow branch that should be executed when no value was found.

Note that besides parameters, you can use first column values to define action properties. See Announcement: Using first column value in action properties

I don't see why you would need custom SQL here. You can do all of that with EasyMorph actions.