How can I get this application to work?

IS THAT OK! not too much experience with instructions check box in the select. I try to have a query that returns a "CR" address if they do not have CM, CM AND are they have a.
They cannot have the two is perhaps a better way of restricted in where clause.
in other words if they record CM give me that address, but if they do not have CM give CR...
Probably an easy things for some of you guys!
Thank you
  select 
spriden_id,         
spbpers_name_suffix   name_suffix,
spbpers_name_prefix   name_prefix,
spriden_last_name     last_name,
spriden_first_name    first_name,
spriden_mi            mi,
srbrecr_term_code,
srbrecr_majr_code,
srbrecr_program_1,
saturn_midd.utlq.f_matl_code_type(srbrecr_pidm), 
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_STREET_LINE1 END, 
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and  SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_CITY END ,
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and  SPRADDR_ATYP_CODE != 'CR' THEN  SPRADDR_STAT_CODE END ,
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and  SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_ZIP END, 
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and  SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_CNTY_CODE END,
CASE WHEN SPRADDR_ATYP_CODE = 'CM'   and  SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_NATN_CODE END,
CASE WHEN SPRADDR_ATYP_CODE = 'CR'   and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_STREET_LINE1 END, 
CASE WHEN SPRADDR_ATYP_CODE = 'CR'   and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_CITY END ,
CASE WHEN SPRADDR_ATYP_CODE = 'CR' and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_STAT_CODE END ,
CASE WHEN SPRADDR_ATYP_CODE = 'CR' and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_ZIP END, 
CASE WHEN SPRADDR_ATYP_CODE = 'CR' and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_CNTY_CODE END,
CASE WHEN SPRADDR_ATYP_CODE = 'CR' and SPRADDR_ATYP_CODE != 'CM' THEN SPRADDR_NATN_CODE END
END
FROM 
saturn.srbrecr, 
saturn.spriden,
saturn.spbpers,
SATURN.SPRADDR 
WHERE 
spriden_pidm = srbrecr_pidm 
AND SPRIDEN_PIDM = SPRADDR_pidm  
--and srbrecr_term_code = decode(p_term  ,'%',SRBRECR_TERM_CODE,p_term)
and spbpers_pidm = spriden_pidm 
and spriden_change_ind is null
and SRBRECR_PROGRAM_1 = 'CMQ'
--AND SPRADDR_ATYP_CODE = 'CM'
AND SPRADDR_STREET_LINE1 IS NOT NULL;
Published by: user648177 on April 22, 2009 08:47

(try lowercase letters for the code of {})

Set apart:

CASE WHEN SPRADDR_ATYP_CODE = 'CM' and SPRADDR_ATYP_CODE != 'CR' THEN SPRADDR_STREET_LINE1 END,
...

which should be rewritten as (*):

CASE WHEN SPRADDR_ATYP_CODE = 'CM' THEN SPRADDR_STREET_LINE1 END cm_street_line_column_alias,
...

your method is going in the right direction.

However, to get the details on a line, you must use an aggregate function, for example. :

MAX(CASE WHEN SPRADDR_ATYP_CODE = 'CM' THEN SPRADDR_STREET_LINE1 END) cm_street_line_column_alias,
...
group by spriden_id, ..., saturn_midd.utlq.f_matl_code_type(srbrecr_pidm)

(*) To put it another way, you're actually saying "If 1 = 1 and 1! = 2 then... "- the second condition is totally redundant as 1 will never be equal 2

Published by: Boneist on April 22, 2009 16:56

Published by: Boneist on April 23, 2009 08:47

Tags: Database

Similar Questions

Maybe you are looking for