Solved

Oracle 9i  Select static values depending on IF

Posted on 2014-07-18
4
320 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)
ID: 40204760
Something like:

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

Author Comment

by:JDCam
ID: 40204825
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
ID: 40204840
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
ID: 40205042
thanks.. this idea works fine
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error in my cursor 5 41
SQL Server group with two values 4 35
TSQL Query Into Specific XML Format w/ Multiple Groupings 6 33
query question 12 32
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

861 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