所以我有一個查詢過濾一堆記錄刪除行:加入其它表沒有具體記錄
declare @rDate_datepart datetime
-- this gets rid of any time information, so we have just the date (i.e, right at midnight of that day)
set @rDate_datepart = convert(datetime,convert(varchar(2),datepart("m",'2/3/2012'))+'/'+convert(varchar(2),datepart("dd",'2/3/2012'))+'/'+convert(varchar(4),datepart("yyyy",'2/3/2012')))
select tq_tran_quote_id, MAX_MATURITY_DT.cm_maturity_dt
from cfo_tran_quote inner join cfo_transaction
on tq_tr_transaction_id = tr_transaction_id
left join com_lock on tr_transaction_id = lk_tr_transaction_id
LEFT OUTER JOIN
(
SELECT cm_tq_tran_quote_id, MAX(cm_maturity_dt) as 'cm_maturity_dt'
FROM cfo_component
GROUP BY cm_tq_tran_quote_id
) AS MAX_MATURITY_DT ON MAX_MATURITY_DT.cm_tq_tran_quote_id = tq_tran_quote_id
where tq_dd_tran_qt_status = 'Matured' and
isnull(lk_rv_lock_status, 10104) = 10104 and
MAX_MATURITY_DT.cm_maturity_dt between @rDate_datepart - 15 and @rDate_datepart
and tq_dd_product in
(select pr_dd_product
from cfo_product
where pr_dd_product_type = 'Cash Flow')
現在我基本上要的東西添加到該查詢,說,給我所有的這行查詢帶回這些特定的tq_tran_quote_id
的沒有記錄在另一個表cfo_daily_trans_hist
其中dh_valuation_total
在那個其他表0
。
這有道理嗎?
我最不善於用SQL ...笑
這是完美的。謝謝! – slandau 2012-02-03 18:38:54