Solved

Oracle 9i  Select static values depending on IF

Posted on 2014-07-18
4
306 Views
Last Modified: 2014-07-18
I have an existing select stmt that returns a billing address
SELECT 
C.Cust_Name AS CUST_NAME,
C.Cust_Add1 AS CUST_ADD1,
C.Cust_add2 AS CUST_ADD2,
Z.ZIP_CITY AS CUST_CITY,
Z.STATE_CODE AS CUST_PROV,
C.zip_code AS CUST_POSTAL
FROM E_ORD_H E
left JOIN M_CUST_H C on C.CUST_CODE = E.CUST_CODE and C.COMP_CODE = E.COMP_CODE
left JOIN M_ZIP Z on Z.ZIP_CODE = C.ZIP_CODE and Z.COUNTRY_CODE = C.COUNTRY_CODE and Z.ZIP_STAT = 'A'
WHERE E.ORD_NUM = (
   select min(D4.ord_num) from E_FRT_ORD_D4 D4 
   where D4.load_num = :p_load_num
   and D4.comp_code_Actual = E.Comp_Code)
AND E.COMP_CODE = :p_comp_code

Open in new window


I need to modify this.  I need to evaluate another field E.ORD_FRT_TERM. If this field is = 'PRE' I want to return hard coded (Static) values for each column. If <> 'PRE' I want to return the original results.
How do I do this?
0
Comment
Question by:JDCam
  • 2
  • 2
4 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
Something like:

...
case when E.ORD_FRT_TERM = 'PRE' then 'staticValue' else E.ORD_FRT_TERM  end
...
0
 

Author Comment

by:JDCam
Comment Utility
Sorry..no
More like

IF E_ORD_FRT_TERM = 'PRE'
     SELECT
     'MY NAME' AS CUST_NAME,
     '123 My STRRE' AS CUST_ADD1,
     'UNIT 123' AS CUST_ADD2,
    'MY CITY' AS CUST_CITY,
    'MY STATE' AS CUST_STATE,
    'MY ZIP' AS CUST_ZIP
ELSE  (Original Query, which returs 6 columns of an address)
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
Do you need this in a single select statement or can you do it in code?

Where does E_ORD_FRT_TERM come from?

If you need a single select maybe something like:

SELECT 
C.Cust_Name AS CUST_NAME,
C.Cust_Add1 AS CUST_ADD1,
C.Cust_add2 AS CUST_ADD2,
Z.ZIP_CITY AS CUST_CITY,
Z.STATE_CODE AS CUST_PROV,
C.zip_code AS CUST_POSTAL
FROM E_ORD_H E
left JOIN M_CUST_H C on C.CUST_CODE = E.CUST_CODE and C.COMP_CODE = E.COMP_CODE
left JOIN M_ZIP Z on Z.ZIP_CODE = C.ZIP_CODE and Z.COUNTRY_CODE = C.COUNTRY_CODE and Z.ZIP_STAT = 'A'
WHERE E.ORD_NUM = (
   select min(D4.ord_num) from E_FRT_ORD_D4 D4 
   where D4.load_num = :p_load_num
   and D4.comp_code_Actual = E.Comp_Code)
AND E.COMP_CODE = :p_comp_code
AND E_ORD_FRT_TERM <>  'PRE'
union all
SELECT
      'MY NAME' AS CUST_NAME,
      '123 My STRRE' AS CUST_ADD1,
      'UNIT 123' AS CUST_ADD2,
     'MY CITY' AS CUST_CITY,
     'MY STATE' AS CUST_STATE,
     'MY ZIP' AS CUST_ZIP
FROM DUAL
where E_ORD_FRT_TERM = 'PRE'

Open in new window

0
 

Author Closing Comment

by:JDCam
Comment Utility
thanks.. this idea works fine
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

762 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

8 Experts available now in Live!

Get 1:1 Help Now