sql select statement to show results if source = B exists then results with source B otherwise results from source O -
i want select report report source 'b' if exists, otherwise report_source 'o'
select r.rep_id, r.rep_name, r.rep_status, r.rep_source o.cmp_id, o.cmp_company_name, o.cmp_company_al company o, report r o.cmp_id = r.rep_cmp_id , r.rep_status in ('n','a') , r.rep_source = ???decode;
output example:
rep_id rep_name rep_status rep_source cmp_id cmp_company_name cmp_company_name_al
100 rep-2000 o 144 asm assist support mgt
120 rep-9900 b 144 asm assist support mgt
i want results if rport source b. if there no report source company show report report source o
so results shown in case:
120 rep-9900 b 144 asm assist support mgt
i think you: (when want select char 'b' in rep_source when present else 'o'. go below code.)
select r.rep_id, r.rep_name, r.rep_status, case when r.rep_source = 'b' 'b' else 'o' end rep_source o.cmp_id, o.cmp_company_name, o.cmp_company_al company o, report r o.cmp_id = r.rep_cmp_id , r.rep_status in ('n','a')
else if want rep_source 'b' or 'o' values. go this:
select r.rep_id, r.rep_name, r.rep_status, r.rep_source, o.cmp_id, o.cmp_company_name, o.cmp_company_al company o, report r o.cmp_id = r.rep_cmp_id , r.rep_status in ('n','a') , r.rep_source ='b' or r.rep_source ='o'
Comments
Post a Comment