Posts

Showing posts with the label COALESCE

COALESCE and IIF functions, the CASE statement and a secret at the end of the post

Image
Hi Friends, March has arrived, spring is coming and i am writing this post after a sunny thuesday. Not bad at all! Just a good coffee and it is time for our basic post of today! We will talk about the COALESCE and IIF functions and the CASE statement.  Maybe someone has never used them or ...doesn't know the secret at the end of the post! Hey don't cheat, don't scroll down! please! COALESCE The function coalesce return the first not null parameter from the left For example: SELECT COALESCE (NULL,1,3) return 1 SELECT COALESCE (‘A’,’B’,’C’) return ‘A’   I like this function because it accepts a variable number of parameters as input. Few functions do this.. In all honesty I would like other functions that behave this way, for example the MAX and MIN... COALESCE, IIF or CASE? There are other ways to get the same result as the following query: Select coalesce (g.qttgiai,g.qttimpi,g.qttmani) from products g   I can use for examp...