mardi 28 mars 2017

shell script if result is null then return result as Zero

I have queried a table using as shell script.

test = select max(id) from database.abc

Now this query result will be used to get data from another table like below

select * from database.table1 where id > test

Now if the table abc has any records it will return the max value of id. Which we will use in the second query.

If the table abc has no records then the query will return a null value. Now what I want to do is whenever the 1st query returns a Null value, then in the second query that value should be taken as Zero.

For example:

In the first query returns test = NULL then the 2nd query should be like below

select * from database.table1 where id > 0

How can I achieve that in shell script in Linux

Aucun commentaire:

Enregistrer un commentaire