COALESCE in SQL Server vs COALESCE in MySQL -


as know coalesce ansi sql standard function. has same functionality across different rdbms (ie) returns first not null value list of values.

consider following data setup

create table tablea (customerid varchar(10), salary int); insert tablea (customerid, salary) values     ('a1', 100),     ('a2', 200),     ('a3', 300),     ('a4',400);  create table tableb (customerid varchar(10), rate int); insert tableb (customerid, rate) values     ('a1', 2),     ('a2', 3),     ('a3', 4); 

query :

select t1.customerid,        coalesce(t1.salary * t2.rate, 'na') salary tablea t1 left join tableb t2     on t1.customerid = t2.customerid 

in sql server when ran above code, generates following error

msg 245, level 16, state 1, line 64 conversion failed when converting varchar value 'na' data type int.

it's because coalesce function convert na integer since integer has higher precedence varchar.

when run same code in mysql works. here demo

my question is, why ansi sql function implemented in 2 different ways in 2 different rdbms(sql server & mysql). till thought ansi sql function behaves in same way in rdbms!

imo, coalesce implemented in same way in both databases achieving goal:

returning first non-null parameter

but there policy in sql server not in mysql, like:

just same values can union 1 column

above policy applied in many queries:
e.g.:

select 1 column1 union select 'c' 

select       case           when 1 1          when 2 'c'      end  ... 

.... 

i think not related implementation of coalesce it's related query policies of databases.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -