COALESCE Sample
-- Coalesce take Comma seprated Fields, it will Take First Non NULL Field Value
Select Coalesce(Afld,BFld,CFld) as NFld, Afld,BFld,CFld From
(
Select 'A' as AFld,'B' as BFld, 'C' as CFld
Union all
Select NULL as AFld,'B' as BFld, 'C' as CFld
Union all
Select NULL as AFld,NULL as BFld, 'C' as CFld
) Alldata
-- Writting Same Logic with out Coalesce using Case when
Select Case when AFld is not null then AFld Else Case when Bfld Is not null then BFld Else Case when Cfld IS not null then Cfld End End End As Nfld
, Afld,BFld,CFld From
(
Select 'A' as AFld,'B' as BFld, 'C' as CFld
Union all
Select NULL as AFld,'B' as BFld, 'C' as CFld
Union all
Select NULL as AFld,NULL as BFld, 'C' as CFld
) Alldata
Comments
Post a Comment