Solved

case statements

Posted on 2011-02-22
6
225 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
ID: 34952727
(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
ID: 34952800
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
ID: 34952805
hi rajvja

how do i fit this into the code shown above as I need the other conditions in the case statement
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 51

Assisted Solution

by:HainKurt
HainKurt earned 170 total points
ID: 34952827
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
ID: 34952848
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
ID: 34952937
Ive split the points thanks guys
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Copy Database Wizard 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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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