Using COALESCE to handle NULL values in PostgreSQL

You can use COALESCE in conjunction with NULLIF for a short, efficient solution: COALESCE( NULLIF(yourField,”) , ‘0’ ) The NULLIF function will return null if yourField is equal to the second value (” in the example), making the COALESCE function fully working on all cases: QUERY | RESULT ——————————————————————————— SELECT COALESCE(NULLIF(null ,”),’0′) | ‘0’ SELECT … Read more

Is there a coalesce-like function in Excel?

=INDEX(B2:D2,MATCH(FALSE,ISBLANK(B2:D2),FALSE)) This is an Array Formula. After entering the formula, press CTRL + Shift + Enter to have Excel evaluate it as an Array Formula. This returns the first nonblank value of the given range of cells. For your example, the formula is entered in the column with the header “a” A B C D … Read more

Using ISNULL vs using COALESCE for checking a specific condition?

This problem reported on Microsoft Connect reveals some differences between COALESCE and ISNULL: an early part of our processing rewrites COALESCE( expression1, expression2 ) as CASE WHEN expression1 IS NOT NULL THEN expression1 ELSE expression2 END. In [this example]: COALESCE ( ( SELECT Nullable FROM Demo WHERE SomeCol = 1 ), 1 ) we generate: … Read more

?? Coalesce for empty string?

C# already lets us substitute values for null with ??. So all we need is an extension that converts an empty string to null, and then we use it like this: s.SiteNumber.NullIfEmpty() ?? “No Number”; Extension class: public static class StringExtensions { public static string NullIfEmpty(this string s) { return string.IsNullOrEmpty(s) ? null : s; … Read more

How to concatenate columns in a Postgres SELECT?

With string type columns like character(2) (as you mentioned later), the displayed concatenation just works because, quoting the manual: […] the string concatenation operator (||) accepts non-string input, so long as at least one input is of a string type, as shown in Table 9.8. For other cases, insert an explicit coercion to text […] … Read more

Oracle Differences between NVL and Coalesce

COALESCE is more modern function that is a part of ANSI-92 standard. NVL is Oracle specific, it was introduced in 80‘s before there were any standards. In case of two values, they are synonyms. However, they are implemented differently. NVL always evaluates both arguments, while COALESCE usually stops evaluation whenever it finds the first non-NULL … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)