SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help!!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

raghunaik
Starting Member

India
1 Posts

Posted - 10/17/2012 :  00:43:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/17/2012 :  06:57:30  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000