【发布时间】:2017-06-26 12:37:08
【问题描述】:
我正在使用以下查询从两个表中获取记录。
我想从不同的表中获取借记金额,结果应该如下所示。
我当前的查询
select VM.voucher_no, VM.vch_date,VM.vch_remarks, case when DT.vch_amt_type2app_elm='Debit' then dt.amount else 0 end as Debitamt,
case when DT.vch_amt_type2app_elm='Credit' then dt.amount else 0 end as Creditamt
from TBL_VOUCHER_DETAIL DT
INNER JOIN TBL_Voucher_Master VM
ON VM.voucher_no = DT.voucherdetail2vmaster
where VM.Vch_Date between '2015-06-17 15:12:51.000' and '2015-06-17 15:12:51.000'
and DT.voucherdetail2ledgers='L00012'
结果如下
Voucher No Voucher Date Remark Debit Credit
49 17/06/2017 a 0 8229
另一个表:- Tbl_invo 字段名称:- Inv no、date、cliName、Total、Dabit。
【问题讨论】:
-
听起来你也需要在 DEBIT 表上加入。
-
那你为什么不能呢?
-
能否再给一个表名和字段pelase
-
谢谢@B House,我已经添加了另一个有问题的表字段..
-
@RavirajJadhav Brill。 Tbl_invoice 到 tbl_vouhcer_master 之间的共同字段是什么?
标签: sql sql-server database