2016-09-22 66 views
0

我試圖連接一個表中的兩個字段和另一個表中的另外兩個字段,並使用連接值作爲主鍵將表連接在一起。使用iReports連接字段和連接表

由於主鍵鏈接到示例5不同的人,我需要一個單獨的值,每個人將一個保單號與一個dep代碼連接起來。

以下是如何使用MSSQL運行查詢的示例(我沒有包含完整的代碼 - 只是一個示例)。

Alter table [beneficiary] add [Unique] varchar(max) 
 
Update [beneficiary] Set [Unique] =concat([t1.ms_fk],[t1.dep_fk]) 
 

 
Alter table [tsf_claim] add [Unique] varchar(max) 
 
Update [tsf_claim] Set [Unique1] =concat([t5.ms_fk],[t5.dep_fk]) 
 

 
LEFT JOIN [mipbi_dbo.td_beneficiary] t5 ON t1.[Unique] = t5.[Unique1]

我需要在iReports上述作爲最終的左連接,我不知道如何在iReports創造更多的領域。另外請注意,我iReports是一個很老的版本(3.7.1)

SELECT t1.scheme_fk,t1.ms_fk,t1.dep_fk,t1.pr_fk,t1.tariff_fk,t1.icd10_fk,t1.claimed_amount,t1.benefit_amount,t1.auth_fk,t1.units,t1.paid_date, 
 
     t1.claim_date,t1.claim_code,t1.ref_pr_fk,t1.note,t1.cheque_datetime,t1.suspend_until,t1.dr_mem,t1.suspended, 
 
     t2.mem_num,t2.xref_num, 
 
     t3.icd10_pk,t3.icd10_descr, 
 
     t4.claim_code,t4.description, 
 
     t5.initials,t5.surname, 
 

 
FROM mipst_dbo.tsf_claim as t1 
 

 
LEFT JOIN mipst_dbo.tsf_memxref  t2 ON t1. ms_fk \t = t2.mem_num 
 
LEFT JOIN mipbi_dbo.td_icd10  t3 ON t1.icd10_fk \t = t3.icd10_pk 
 
LEFT JOIN mipst_dbo.tsd_ccdesc \t  t4 ON t1.claim_code = t4.claim_code::integer 
 
LEFT JOIN mipbi_dbo.td_beneficiary t5 ON t1.ms_fk  = t5.ms_pk 
 

 
WHERE t1.scheme_fk = '75' 
 
\t 
 
GROUP BY t1.scheme_fk,t1.ms_fk,t1.dep_fk,t1.pr_fk,t1.tariff_fk,t1.icd10_fk,t1.claimed_amount,t1.benefit_amount,t1.auth_fk,t1.units,t1.paid_date, 
 
     t1.claim_date,t1.claim_code,t1.ref_pr_fk,t1.note,t1.cheque_datetime,t1.suspend_until,t1.dr_mem,t1.suspended, 
 
     t2.mem_num,t2.xref_num, 
 
     t3.icd10_pk,t3.icd10_descr, 
 
     t4.claim_code,t4.description, 
 
     t5.initials,t5.surname

通過添加LEFT JOIN 'LEFT JOIN mipbi_dbo.td_beneficiary T5 ON t1.ms_fk = t5.ms_pk' 它不根據相關代碼添加人員姓名。這僅僅是加入線路。

總之一個保單號被鏈接到不同的人有一個相關的代碼,所以加入信息DEP 1時,應該鏈接到第二個表1 DEP用正確的姓名等

在表1 dep 1可以說10行,因此使用當前代碼,它將在10行上添加保單號的所有信息,而不僅僅是dep 1的信息。

讓我知道上述內容是否明確定義或者如果你需要更多的信息。

回答

0

我是能夠解決查詢僅僅通過

SELECT t1.scheme_fk,t1.ms_fk,t1.dep_fk,t1.pr_fk,t1.tariff_fk,t1.icd10_fk,t1.claimed_amount,t1.benefit_amount,t1.auth_fk,t1.units,t1.paid_date, 
 
     t1.claim_date,t1.claim_code,t1.ref_pr_fk,t1.note,t1.cheque_datetime,t1.suspend_until,t1.dr_mem,t1.suspended, 
 
     t2.mem_num,t2.xref_num, 
 
     t3.icd10_pk,t3.icd10_descr, 
 
     t4.claim_code,t4.description,t4.scheme_code, 
 
     t5.ms_pk,t5.dep_fk,t5.initials,t5.surname, 
 
     t6.narration,t6.key 
 

 
FROM mipst_dbo.tsf_claim as t1 
 

 
LEFT JOIN mipst_dbo.tsf_memxref  t2 ON t1. ms_fk \t = t2.mem_num 
 
LEFT JOIN mipbi_dbo.td_icd10  t3 ON t1.icd10_fk \t = t3.icd10_pk 
 
LEFT JOIN mipst_dbo.tsd_ccdesc \t  t4 ON t1.claim_code = t4.claim_code::integer 
 
LEFT JOIN mipbi_dbo.td_beneficiary t5 ON t1.ms_fk  = t5.ms_pk 
 
LEFT JOIN mipst_dbo.tsf_note \t  t6 ON t1.note  = t6.key 
 

 
WHERE t1.scheme_fk = '28' and 
 
\t  t4.scheme_code = '28' and 
 
     t1.ms_fk = t5.ms_pk AND 
 
     t1.dep_fk =t5.dep_fk 
 
    
 
\t 
 
GROUP BY t1.scheme_fk,t1.ms_fk,t1.dep_fk,t1.pr_fk,t1.tariff_fk,t1.icd10_fk,t1.claimed_amount,t1.benefit_amount,t1.auth_fk,t1.units,t1.paid_date, 
 
     t1.claim_date,t1.claim_code,t1.ref_pr_fk,t1.note,t1.cheque_datetime,t1.suspend_until,t1.dr_mem,t1.suspended, 
 
     t2.mem_num,t2.xref_num, 
 
     t3.icd10_pk,t3.icd10_descr, 
 
     t4.claim_code,t4.description,t4.scheme_code, 
 
     t5.ms_pk,t5.dep_fk,t5.initials,t5.surname, 
 
     t6.narration,t6.key

更新where子句。