Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL If then else Query

DonGROct 21 2015 — edited Oct 21 2015

Hello,

I am an Oracle SQL newbie and wondered if it was possible to query a database column and if a condition is met select these column if not select a different column?

Background: We have a legacy database that's been recently migrated, now during this transitioning period all new entries will use the same logical name but use totally different primary keys (IDs).

So, we have 2 tables one table primary key starting with "C" and the other table primary key starts with "P", I can retrieve host names in the "C" table which does contents "C" & "P" primary keys but since "P" table columns does not line-up with "C" table there is no way I can retrieve other relevant details if the primary key begins with "P".

The SQL query below is what I want to achieve but do not know enough too write the correct SQL statements.

I am lost and not sure if this is possible, any help would be greatly appreciated.

Thanks in advance,

Don

Select i.TICKET_ID_, i.PROBLEM_ID, t.INV_ID

If t.INV_ID = "P%" then

Select p.name, p.SYSTEM, p.IMPACT, p.MODEL_NUMBER

Else

Select t.COMPONENT, c.OPERATING_SYSTEM, c.ESCALATION_IMPACT, c.MODEL

End if

FROM MANAGEMENT i

JOIN Module t

ON i.ticket_id_ = t.ticket_id_

LEFT JOIN HARDWARE c

ON t.INV_ID = c.INV_ID

LEFT JOIN COMPUTER_SYSTEM p

ON t.COMPONENT = p.name

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 18 2015
Added on Oct 21 2015
7 comments
1,130 views