Meta-SQL %Coalesce

If you're like me, you might first wonder what the word Coalesce even means? Well in terms of SQL constructs, it refers dealing with NULL values. If you're an Oracle user, you might be more familiar with the nvl operation.

A common use for coalesce/nvl is to substitute a default value when a null is encountered. Probably the most common example is to substitute a null with a 0 on fields you are using for calculations.

So for example:

select QTY * PRICE from YOUR_TABLE;

Works fine unless you have a scenario where either the quantity or price is NULL. Yes that may be weird but this is meant to be an example. Here's how to write the same statement with coalese using Meta-SQL:

select %Coalesce(QTY, 0) * %Coalesce(PRICE, 0)

Simple, on resolving the Meta-SQL it will be turned into the appropriate syntax for your database platform. If you use Oracle you might wonder why you would bother when you can just use nvl? Well like a lot of other Meta-SQL functions, the benefit is database platform independence. Your code will work on any database supported by PeopleSoft. Up to you.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License