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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help!!

Author  Topic 

raghunaik
Starting Member

1 Post

Posted - 2012-10-17 : 00:43:43
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 below

Input table
Vendor Parent Vendor Group Vendor Name Spend Month
NULL NULL Midas touch 11234 September
NULL NULL Midas touch 2323 October
NULL NULL Midas touch 12324 November
Go Live Co NULL Go Live 232 October
Go Live Co NULL Go Live 1342 November
Paradigm Com Paradigm Co Paradigm 12372 September
Paradigm Com Paradigm Co Paradigm 809 October


Output table

Vendor Parent Vendor Group Vendor Name Spend Month
Midas touch Midas touch Midas touch 11234 September
Midas touch Midas touch Midas touch 2323 October
Midas touch Midas touch Midas touch 12324 November
Go Live Co Go Live Go Live 232 October
Go Live Co Go Live Go Live 1342 November
Paradigm Com Paradigm Co Paradigm 12372 September
Paradigm 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]
Go to Top of Page
   

- Advertisement -