Solved

case statements

Posted on 2011-02-22
6
198 Views
Last Modified: 2012-05-11
Hi experts

I have a problem and I hope someone can help

I have attached a case statement which I am working on and im having a problem with the null values

What I would like to do is when i.add_3 is null then I want the value of i.add_2 to be placed in the new column 'town'

Can anyone see where I am going wrong

Thanks
(case i.add_3 

	when 'Co Londonderry' then i.add_2
	when 'Co Antrim' then i.add_2
	when 'County Londonderry' then i.add_2
	when 'Co Tyrone' then i.add_2
	when 'Co Derry' then i.add_2
--	when isnull(i.add_3,i.add_2) -- this line is incorrect
	else i.add_3 end) as 'town',

Open in new window

0
Comment
Question by:lisa_mc
6 Comments
 
LVL 11

Accepted Solution

by:
rajvja earned 165 total points
Comment Utility
(case when i.add_3  is null then i.add_2 end as town)
 
0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 165 total points
Comment Utility
Try:

(case i.add_3 

	when 'Co Londonderry' then i.add_2
	when 'Co Antrim' then i.add_2
	when 'County Londonderry' then i.add_2
	when 'Co Tyrone' then i.add_2
	when 'Co Derry' then i.add_2
	else isnull(i.add_3,i.add_2)  
        end) as 'town',

Open in new window

0
 
LVL 3

Author Comment

by:lisa_mc
Comment Utility
hi rajvja

how do i fit this into the code shown above as I need the other conditions in the case statement
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 170 total points
Comment Utility
try:

(case  
      when i.add_3='Co Londonderry' then i.add_2
      when i.add_3='Co Antrim' then i.add_2
      when i.add_3='County Londonderry' then i.add_2
      when i.add_3='Co Tyrone' then i.add_2
      when i.add_3='Co Derry' then i.add_2
      when i.add_3 is null then i.add_2 -- this line is incorrect
      else i.add_3 end) as 'town',
0
 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 170 total points
Comment Utility
is this doing the same thiong?

(
case  
when  i.add_3 is null or i.add_3 in ('Co Londonderry','Co Antrim','County Londonderry','Co Tyrone','Co Derry') then i.add_2
else i.add_3 end
) as 'town',
0
 
LVL 3

Author Closing Comment

by:lisa_mc
Comment Utility
Ive split the points thanks guys
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now