We help IT Professionals succeed at work.
Get Started

SQL select case when and retrieve level2 and level3 from string

Luis Diaz
Luis Diaz asked
on
96 Views
Last Modified: 2015-03-16
Hello Experts,

I have the following query select id, organization1, organization2 from project

And the corresponding data

Id; organization1;organization2
5858;level1.level2.level3.level4.level5;
58968;; titi1.titi2.titi3.titi4.titi5

As you can see sometimes organization2 doesn’t have data the same for organization1

I need to perform a sql query that does the following:

Select case when Organization1 is not null take into account Organization 1 else take into Organization2 as OrganizationRevised. If both are not null take into account Organization 1

Select just level2.level3 of OrganizationRevised

Final result

Id Organization Revised
5858;level2.level3
58968;titi2.titi3

Thank you for your help.
Comment
Watch Question
Senior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 3 Answers and 30 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE