Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have an input table and have few rows for which I would like to update the values. not sure how to include a file hence pasted the input and output table belowInput table Vendor Parent Vendor Group Vendor Name Spend MonthNULL NULL Midas touch 11234 SeptemberNULL NULL Midas touch 2323 OctoberNULL NULL Midas touch 12324 NovemberGo Live Co NULL Go Live 232 OctoberGo Live Co NULL Go Live 1342 NovemberParadigm Com Paradigm Co Paradigm 12372 SeptemberParadigm Com Paradigm Co Paradigm 809 OctoberOutput tableVendor Parent Vendor Group Vendor Name Spend MonthMidas touch Midas touch Midas touch 11234 SeptemberMidas touch Midas touch Midas touch 2323 OctoberMidas touch Midas touch Midas touch 12324 NovemberGo Live Co Go Live Go Live 232 OctoberGo Live Co Go Live Go Live 1342 NovemberParadigm Com Paradigm Co Paradigm 12372 SeptemberParadigm Com Paradigm Co Paradigm 809 October
Case when pg.Parent is not null then pg.Parent else (Case when pg.Vendor_group is not null then pg.Vendor_group else coalesce(rtrim(ve.EnglishNm), ve.VendorNm)end )end as [Vendor Parent], Case when pg.Vendor_group is not null then pg.Vendor_group else coalesce(rtrim(ve.EnglishNm), ve.VendorNm)end as [Vendor Group], coalesce(rtrim(ve.EnglishNm), ve.VendorNm) [Vendor Name],
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts
Posted - 2012-10-17 : 06:57:30
You can use coalesce with more than two parameters, as shown below:
SELECT COALESCE (pg.Parent,pg.Vendor_group,RTRIM(ve.EnglishNm), ve.VendorNm) AS [Vendor Parent], COALESCE (pg.Vendor_group,RTRIM(ve.EnglishNm), ve.VendorNm) AS [Vendor Group], COALESCE(RTRIM(ve.EnglishNm), ve.VendorNm) [Vendor Name]