troubleshooting Question

PL/SQL Select statement with If-Then-Else condition

Avatar of reignsupreme
reignsupreme asked on
Oracle DatabaseSQL
14 Comments1 Solution473 ViewsLast Modified:
I have a select statement that requires a condition to return the proper value in 1 of the columns, here is my syntax and an example of what I need returned in the last column "REASON"

SELECT DISTINCT
     SI.LABEL SITENAME,
     P.SCREENNUM,
     P.RANDNUM,
     P.LABEL,
     P.PATINIT,
     P.SFAILREASONID,
     P.REASONID,
     P.CRITERID,
     TO_CHAR(P.SCREENDT, 'DD-MON-YYYY') SCREENDT ,
     S.VALUE STATUS,
     LTRIM(C.LABEL)  SFAILTEXT,
     LTRIM(C2.LABEL)  PFAILTEXT,
     C.LABEL ||'  '|| P.CRITERID ||'  '|| P.SFAILCOMMENT REASON  
 FROM
     PNPATIENT_VIEW P,
     PNSITE SI,
     PATIENTSTATUSLIST_VIEW S,
     SCREENFAILREASONS_VIEW C,
     SCREENFAILREASONS_VIEW C2,
     PNSEARCH_VIEW  V1,
     PNSEARCH_VIEW  V2
 WHERE P.SFAILREASONID = C.CODE (+)
      AND P.REASONID = C2.CODE (+)
      AND P.STATUS = S.CODE (+)
      AND SI.SUBMODINSTID = P.SITEID(+)
      AND P.SITEID =   TO_NUMBER(V1.VALUE)
      AND P.SUBMODINSTID =    TO_NUMBER(V2.VALUE)

The condition is:

if (p.reasonid is not null) and (c.sfailreasonid is null) then
 ltrim(c.label) sfailtext
else
  ltrim(c.label) sfailtext
end if
ASKER CERTIFIED SOLUTION
Daniel Wilson

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros