All Forums Database
sandi99 2 posts Joined 03/16
26 Jul 2016
Help Combing Two Queries

Hi there - very novice at SQL.  Looking to combine two queries and not sure how to go about. I am trying to add company_name to Query 1.  company_name is in Query 2 which uses two entirely different tables.  Of course, I am at a loss here.  Appreciate any assistance!  Thanks in advance!
Query 1 uses: 
- se_qba = pulls customer data  * NEED TO LINK cust_acct_nbr to cvmH table *
- employee_assignment AND employee = pulls employee data
Query 2 uses:
- cvmH AND cvmE = pulls company name * NEED TO LINK cust_acct_nbr from cvmH table to se_qba table *
 
Query 1:  Returns customer data and employee data.  Does not return customer name.

select
enti_nbr,
cust_acct_nbr,
TRIM (a.sales_div_nbr) || '-' || TRIM (a.sales_grp_nbr) || '-' || TRIM (a.sales_org_nbr)  || '-' || TRIM (a.sales_rgn_nbr)  || '-' || TRIM (a.sales_area_nbr)  || '-' || TRIM (a.sales_dist_nbr) || '-' || TRIM (a.sales_terr_nbr) AS Territory,
b.first_nm || ' ' || b.last_nm AS name

from  se_qba seqba
left join employee_assignment a on seqba.sale_terr_cd = Territory
left join employee b on a.emp_nbr = b.emp_nbr 

where a.exp_dt ='05/31/2525'
and seqba.cust_acct_nbr in ( '999999999' )
and seqba.sale_terr_globl_rgn_cd = 'CAN'
and align_type_cd = 'P'

Query 2:  Returns customer name.

select 
​co_name 

from cpv_db.cvmH a
left join cpv_db.cvmE b on a.cvm_nbr = b.cvm_nbr

where cust_acct_nbr = '999999999'
and CURRENT_TIMESTAMP between a.eff_tmstp and a.expr_tmstp

 
 

M.Saeed Khurram 544 posts Joined 09/12
27 Jul 2016

Can you share the DDLs of both these tables?

Khurram

sandi99 2 posts Joined 03/16
27 Jul 2016

Hi there Khurram...sorry...I am not exactly sure what you are looking for.  Could you please elaborate?  Thanks!
 

You must sign in to leave a comment.