Oracle SQL - connecting 2 dates - sql

I have the following code.
It has 2 dates:
1.
(case
when not trunc(iv.dated) is null then trunc(iv.dated) else trunc(iv1.dated)
end) date_stock_received
2.
trunc(dh.actshpdate) SHIP_DATE
Is there a way to join the dates so they show in one column?
select unique li.catnr, li.av_part_no,
(select sum(pl.qty_onhand) from part_loc pl where li.av_part_no = pl.part_no) qty_onhand,
(case
when not trunc(iv.dated) is null then trunc(iv.dated) else trunc(iv1.dated)
end) date_stock_received,
(case
when not sum(iv.quantity) is null then sum(iv.quantity) else sum(iv1.quantity)
end) qty_received,
dp.delqty, od.ord_extordnr, trunc(dh.actshpdate) SHIP_DATE
from leos_item li
LEFT JOIN scm_packtyp sp
ON li.packtyp = sp.packtyp
LEFT JOIN invtran_view_oes iv
ON li.av_part_no = iv.part_no
and (iv.transaction = 'NREC' and iv.location_no = ' RETURNS W')
LEFT JOIN invtran_view_oes iv1
on li.av_part_no = iv1.part_no
and (iv1.transaction = 'CORR+' and iv1.remark like 'STOCK FROM SP PALLET%')
LEFT JOIN oes_delsegview od
ON od.catnr = li.catnr
and od.prodtyp = li.prodtyp
and od.packtyp = li.packtyp
LEFT JOIN oes_dpos dp
ON od.ordnr = dp.ordnr
and od.posnr = dp.posnr
and od.segnr = dp.segnr
LEFT JOIN oes_dhead dh
on dp.dheadnr = dh.dheadnr
and dh.shpfromloc = 'W'
where li.cunr = '816900'
and substr(li.catnr,1,5) in ('RGMCD','RGJCD')
and li.item_type = 'FP'
and li.catnr = 'RGJCD221'
group by li.catnr, li.av_part_no, iv.dated, iv.quantity, iv1.dated, iv1.quantity, dp.delqty,
dp.ordnr, dp.posnr, dp.segnr, od.ord_extordnr, dh.actshpdate
order by li.av_part_no
Current result is ...
... what I would like to see is ...
Is this possible ?

The coalesce function might be what you want.
select trunc(coalesce(iv.dated, iv1.dated, dh.actshpdate)) theDateYouMightWant

Related

How to use SQL Conditional statements in SQL

I'm working on a BIRT Reporting. What I need to do is, If the Column1 value is Approved, Copy Column 2 value to Column 3 else null
SELECT pr.prnum,prline.prlinenum,prline.itemnum,prline.description,prline.orderqty,prline.ponum,pr.status as "PRSTATUS",
postatusappr.changedate as "POAPPRDATE", matrectrans.actualdate as "ACTUALDELIVDATE", prstatuswappr.changedate as "PRCREATED",
prstatusappr.changedate as "PRAPPRDATE", days (current date) - days(date(prstatusappr.changedate)) as "NOOFDAYSAFTERPRAPPR",
INTEGER(days (current date) - days(date(prstatusappr.changedate)))/7 as "NOOFWEEKSAFTERPRAPPR",
INTEGER(days (current date) - days(date(postatusappr.changedate)))/7 as "NOOFWEEKSAFTERPOAPPR" FROM pr pr
LEFT JOIN prline prline ON prline.prnum = pr.prnum AND prline.siteid = pr.siteid
LEFT JOIN poline poline ON poline.ponum = prline.ponum AND poline.siteid = pr.siteid
LEFT JOIN postatus postatusappr ON postatusappr.ponum = poline.ponum AND postatusappr.siteid = pr.siteid AND postatusappr.status = 'APPR'
LEFT JOIN matrectrans matrectrans ON matrectrans.ponum = poline.ponum AND matrectrans.polinenum = poline.polinenum AND matrectrans.positeid = pr.siteid AND matrectrans.issuetype='RECEIPT' AND matrectrans.status = 'COMP'
LEFT JOIN prstatus prstatuswappr ON prstatuswappr.prnum = pr.prnum AND prstatuswappr.status = 'WAPPR' AND prstatuswappr.siteid = pr.siteid
LEFT JOIN prstatus prstatusappr ON prstatusappr.prnum = pr.prnum AND prstatusappr.status = 'APPR' AND prstatusappr.siteid = pr.siteid
where prline.itemnum is not null;
You may try doing an UPDATE with a CASE expression, something like this:
UPDATE yourTable
SET Column3 = CASE WHEN Column1 = 'Approved' THEN Column2 ELSE NULL END;

A new row for each record

I would like the results to produce a new row in each instance where a condition is met. I'm using a CASE statement but this isn't the way to go since once the first condition is met it stops evaluating the field.
SELECT
Reviews.ReviewID,
CASE
WHEN Score_CorrectID = 0 THEN 'Correct ID Right Party Authentication'
WHEN Score_ProperlyIdentified = 0 THEN 'PCA Properly Identified Itself'
WHEN Score_MiniMiranda = 0 THEN 'Mini-Miranda'
END AS [Error Type]
FROM Reviews INNER JOIN PCAs ON Reviews.PCAID = PCAs.PCAID LEFT JOIN
PCARebuttal ON Reviews.ReviewID = PCARebuttal.ReviewID
WHERE
(Score_CorrectID = 0 OR Score_ProperlyIdentified = 0 OR Score_MiniMiranda =
0)
This produces this:
I would like this:
Use apply:
SELECT r.ReviewID, v.error_type
FROM Reviews r INNER JOIN
PCAs
ON r.PCAID = PCAs.PCAID LEFT JOIN
PCARebuttal pr
ON r.ReviewID = pr.ReviewID OUTER APPLY
(SELECT *
FROM (VALUES (Score_CorrectID, 'Correct ID Right Party Authentication'),
(Score_ProperlyIdentified, 'PCA Properly Identified Itself'),
(Score_MiniMiranda, 'Mini-Miranda')
) v(score, error_type)
WHERE score = 0
) v
WHERE (Score_CorrectID = 0 OR Score_ProperlyIdentified = 0 OR Score_MiniMiranda = 0);
That said, I would probably just concatenate the values into a single column:
SELECT r.ReviewID,
( (CASE WHEN Score_CorrectID = 0 THEN 'Correct ID Right Party Authentication; ' ELSE '' END) +
(CASE WHEN Score_ProperlyIdentified = 0 THEN 'PCA Properly Identified Itself; ' ELSE '' END) +
(CASE WHEN Score_MiniMiranda = 0 THEN 'Mini-Miranda;' ELSE '' END)
) as error_types
FROM Reviews r INNER JOIN
PCAs
ON r.PCAID = PCAs.PCAID LEFT JOIN
PCARebuttal pr
ON r.ReviewID = pr.ReviewID OUTER APPLY
(SELECT *
FROM (VALUES ()
) v(score, error_type)
WHERE score = 0
) v
WHERE (Score_CorrectID = 0 OR Score_ProperlyIdentified = 0 OR Score_MiniMiranda = 0);
Instead of using case, you can use union all instead:
SELECT
Reviews.ReviewID,
'Correct ID Right Party Authentication' AS [Error Type]
FROM Reviews
INNER JOIN PCAs ON Reviews.PCAID = PCAs.PCAID
LEFT JOIN PCARebuttal ON Reviews.ReviewID = PCARebuttal.ReviewID
WHERE Score_CorrectID = 0
UNION ALL
SELECT
Reviews.ReviewID,
'PCA Properly Identified Itself' AS [Error Type]
FROM Reviews
INNER JOIN PCAs ON Reviews.PCAID = PCAs.PCAID
LEFT JOIN PCARebuttal ON Reviews.ReviewID = PCARebuttal.ReviewID
WHERE Score_ProperlyIdentified = 0
UNION ALL
SELECT
Reviews.ReviewID,
'Mini-Miranda' AS [Error Type]
FROM Reviews
INNER JOIN PCAs ON Reviews.PCAID = PCAs.PCAID
LEFT JOIN PCARebuttal ON Reviews.ReviewID = PCARebuttal.ReviewID
WHERE Score_MiniMiranda = 0

CURSOR is not displaying data/result set

I've tried everything I could and i still can't get my cursor to display data. here is my code:
DECLARE
CURSOR SL_Cur IS
select *
from (
select
cdav.bank_id,
ent.bank_desc Bank_Description,
cdav.sol_id,
sol.sol_desc SOL_Description,
cdav.gl_sub_head_code GLSH_Code,
decode(cdav.gl_sub_head_code,
'10301',1,
'10403',2, '60403',2, '10501',2, '60501',2, '10502',2,
'10503',2, '10504',2, '10505',2, '10507',2, '10509',2,
'60509',2, '10511',2, '10518',2, '60518',2, '10523',2,
'60523',2, '10551',2, '10552',2, '10553',2, '10554',2,
'10555',2, '10557',2, '10559',2, '10561',2, '10568',2,
'10573',2,
'12336',3, '62336',3, '10401',3, '60402',3, 4 ) GLSH_SET ,
gsh.gl_sub_head_desc GLSH_Name,
case
when (cast(substr(cdav.gl_sub_head_code,0,1) as int) >= 1
and cast(substr(cdav.gl_sub_head_code,0,1) as int) <= 5)
then 'R'
when cast(substr(cdav.gl_sub_head_code,0,1) as int) = 0
or (cast(substr(cdav.gl_sub_head_code,0,1) as int) >= 6
and cast(substr(cdav.gl_sub_head_code,0,1) as int) <= 9)
then 'F'
end book_type,
gam.foracid account_number,
gam.acct_name,
cdav.tran_crncy_code Tran_Currency,
cdav.value_date,
cdav.tran_date Transaction_Date,
cdav.gl_date,
cdav.tran_particular,
rank() over(partition by gam.foracid order by eab.eod_date desc) eod_date_rank,
eab.eod_date,
case when
(select tran_date_bal from tbaadm.eab
where eab.eod_date = (select max(eab.eod_date) from tbaadm.eab
where cdav.acid = eab.acid and eab.eod_date < '28-MAY-2013')
and cdav.acid = eab.acid
and cdav.bank_id = eab.bank_id) is not null
then (select tran_date_bal from tbaadm.eab
where eab.eod_date = (select max(eab.eod_date) from tbaadm.eab
where cdav.acid = eab.acid and eab.eod_date < '28-MAY-2013')
and cdav.acid = eab.acid
and cdav.bank_id = eab.bank_id)
else 0
end beg_tran_date_bal,
(select tran_date_bal from tbaadm.eab eab
where eod_date = (select max(eab.eod_date) from tbaadm.eab eab
where cdav.acid = eab.acid and eab.eod_date <= '28-MAY-2013')
and cdav.acid = eab.acid
and cdav.bank_id = eab.bank_id) end_tran_date_bal,
ott.ref_num OAP_Ref_No,
trim(cdav.tran_id) Transaction_ID,
--cdav.dth_init_sol_id Initiating_SOL_ID,
'PCC_Code',
cdav.tran_rmks Tran_Remarks,
case
when (cdav.part_tran_type = 'D')
then (cdav.tran_amt)
end dr_amount,
case
when (cdav.part_tran_type = 'C')
then (cdav.tran_amt)
end cr_amount
from tbaadm.ctd_dtd_acli_view cdav
left outer join tbaadm.gam
on cdav.bank_id = gam.bank_id and cdav.acid = gam.acid
left outer join tbaadm.gsh
on gam.bank_id = gsh.bank_id and gam.sol_id = gsh.sol_id
and gam.gl_sub_head_code = gsh.gl_sub_head_code
and gam.acct_crncy_code = gsh.crncy_code
left outer join tbaadm.sol
on cdav.bank_id = sol.bank_id and cdav.sol_id = sol.sol_id
left outer join tbaadm.eab
on gam.bank_id = eab.bank_id and gam.acid = eab.acid
left outer join tbaadm.cnc
on gam.bank_id = cnc.bank_id and gam.acct_crncy_code = cnc.crncy_code
left outer join crmuser.end ent
on cdav.bank_id = ent.bank_id
left outer join tbaadm.gct
on cdav.bank_id = gct.bank_id
left outer join tbaadm.ott
on cdav.tran_id = ott.tran_id and cdav.tran_date = ott.tran_date
and cdav.part_tran_srl_num = ott.part_tran_srl_num
and cdav.bank_id = ott.bank_id and cdav.acid = ott.acid
where
gam.acct_ownership = 'O'
and cdav.bank_id = 'CBC01'
and cdav.gl_date = '28-MAY-2013'
and (gam.gl_sub_head_code in ('10301','10403','60403',
'10501','60501','10502','10503','10504','10505',
'10507','10509','60509','10511','10518','60518',
'10523','60523','10551','10552','10553','10554',
'10555','10557','10559','10561','10568','10573',
'12336','62336','10401','60402')
or gam.acct_classification_flg in ('I','E')
)
and trim(cdav.del_flg) in ('N', null)
and trim(gam.del_flg) in ('N', null)
and trim(gsh.del_flg) in ('N', null)
and trim(sol.del_flg) in ('N', null)
and trim(cnc.del_flg) in ('N', null)
and trim(gct.del_flg) in ('N', null)
)
where
eod_date_rank = 1
and GLSH_SET = 1
order by
bank_id,
sol_id,
tran_currency,
glsh_code,
book_type desc,
account_number,
transaction_date;
in_sl_rec SL_Cur%ROWTYPE;
BEGIN
open SL_Cur;
LOOP
FETCH SL_Cur INTO in_sl_rec;
exit when SL_Cur%notfound;
END LOOP;
close SL_Cur;
END;
At first, I just need to make the CURSOR display the result set that I want to see. Next, I want to make the cursor into a sort of FOR LOOP, because there would be input parameters involved when executing the code in iReport, mainly a date range.
Cursors don't just "display" when you execute them - you have to write a little code to do that. Try adding the following lines in your loop after the exit when SL_Cur%notfound; and just before the END LOOP;
DBMS_OUTPUT.PUT_LINE('BANK_ID=' || in_sl_rec.BANK_ID ||
'Bank_Description=' || in_sl_rec.Bank_Description ||
'sol_id=' || in_sl_rec.sol_id ||
'SOL_Description=' || in_sl_rec.SOL_Description);
You can add more fields as you need to.
Share and enjoy.

How to get the max date for multiple conditions

A bit new to Oracle specific SQL syntax, more familiar with MS SQL Server.
I'm having trouble with a join.
Specifically, the join is supposed to allow me to return the most recent date from a table. (In SQL Server I would just put select top 1 date order by date---with oracle it is confusing!)
Here is my entire query, I'm trying to return the max date for each of the date columns in the select statement with the MAX( prefix. (I know the max prefix isn't the correct syntax to get what I'm after, I'm just listing that here so you know which dates I need max date back on..) How do I get the most current date back for those columns?:
SELECT DISTINCT
req.LCR_REQUEST_ID "Request_ID"
,req.MATTER_ID AS "MatterID_lcr"
,req.CUSTOMER_NAME AS "AccountName_lcr"
,req.STATUS AS "CurrentContractStatus_lcr"
,MAX(HIS.RECORDED_DATE) AS "CurrentStatus_ChangeDate"
--,HIS.STATUS AS "ContractStatus_Historic_lcr"
,MAX(HIS_SUB.RECORDED_DATE) AS "Submitted_Status_Date"
--,HIS_NA.RECORDED_DATE AS "NotAssigned_Status_Date"
,MAX(HIS_AtA.RECORDED_DATE) AS "AssignedToAttorney_Status_Date"
,MAX(HIS_SCIN.RECORDED_DATE) AS "InNegotiation_Status_Date"
,MAX(HIS_EXE.RECORDED_DATE) AS "Executed_Status_Date"
,MAX(HIS_CONV.RECORDED_DATE) AS "ConverteToAmend_Status_Date"
,MAX(HIS_DEAD.RECORDED_DATE) AS "Dead_Status_Date"
,MAX(HIS_COMP.RECORDED_DATE) AS "Completed_Status_Date"
,MAX(HIS_EXP.RECORDED_DATE) AS "Expired_Status_Date"
,CASE
WHEN req.DEALSIZE = 0 THEN ''
WHEN req.DEALSIZE = 1 THEN 'Less Than 100K'
when req.DEALSIZE = 2 THEN '100K-500K'
when req.DEALSIZE = 3 THEN '500K-1M'
when req.DEALSIZE = 4 THEN '1M-10M'
when req.DEALSIZE = 5 THEN '>10M'
END
AS "DealSize_lcr"
,cm_out.PTY_NAME AS "AccountName_cm"
,cm_out.PTY_ID AS "PTYID_CM"
,req.customer_id "PtyID_lcr"
,cm_out.EFFECTIVE_DATE "EffDate_lcr"
,cm_out.INITIALTERM_END_DATE "CPEDate_lcr"
,cm_out.CONTRACT_TERMINATION_DATE "FCTDate_lcr"
,cm_out.TERM_NOTICE_NONCOMP_REASON "ReasonForTermination_lcr"
,cm_out.TERM_TYPE "TermType_lcr"
,cm_out.INITIALTERM_DURATION "InitialTerm_lcr"
,cm_out.INVOICE_TIMEMEAS "InitialTermTymeMeas_lcr"
,cm_out.NUMBER_OF_RENEWALS "NumberOfRenewals_lcr"
,req.AMENDMENT "ParentMatterID_lcr"
,prod.rpg "RPG_lcr"
,prod.SALES_PRODUCT_NAME "Product_lcr"
,prod.CONTRACT_TYPE "ContractType_lcr"
,req.CONTRACT_ROLE "ContractRole_lcr"
,cm_out.METADATA_FLAG "MetaFlag_lcr"
,CASE
WHEN cm_out.DATA_AUTO_IMPORT_YN = 1 THEN 'YES'
WHEN cm_out.REQUESTOR = 'Imported Record' THEN 'YES'
ELSE 'NO'
END
"DataImport_lcr"
,CASE act.actionstatus
WHEN 'Cancel Date Update' THEN 'Yes'
ELSE NULL
END "ActionToCancelAutoDate_lcr"
,req_emp.FIRST_NAME || ' ' || req_emp.LAST_NAME "Requestor_lcr"
,att_emp.FIRST_NAME || ' ' || att_emp.LAST_NAME "Attorney_lcr"
,req.REQUESTOR_DEPARTMENT "Requestor_Department_lcr"
,req.AGREEMENT_TITLE "AgreementTitle_lcr"
,req.DATE_RECORDED
FROM LCR_REQUEST REQ
LEFT JOIN LCR_ACTION ACT ON req.MATTER_ID = act.MATTER_ID
LEFT JOIN CM_CONTRACT_OUTBOUND cm_out ON cm_out.MATTER_ID = NVL(req.MATTER_ID,req.AMENDMENT)
LEFT JOIN LCR_REQUEST_PRODUCT prod_REQ ON prod_req.LCR_REQUEST_ID = req.LCR_REQUEST_ID
LEFT JOIN LCR_PRODUCT PROD ON prod.PRODUCT_ID = prod_req.PRODUCT_ID
LEFT JOIN LCR_EMPLOYEE att_emp ON req.ASSIGNED_TO = att_emp.ORACLE_PERSON_ID
LEFT JOIN LCR_EMPLOYEE req_emp ON req.REQUESTED_BY_ID = req_emp .ORACLE_PERSON_ID
LEFT JOIN LCR_STATUS_HISTORY HIS ON HIS.LCR_REQUEST_ID = req.LCR_REQUEST_ID AND ((HIS.STATUS = REQ.STATUS) OR (HIS.STATUS = 'Assigned to Attorney' AND REQ.STATUS = 'Assigned To Attorney'))
--LEFT JOIN LCR_STATUS_HISTORY HIS_NA ON req.LCR_REQUEST_ID = HIS_NA.LCR_REQUEST_ID AND HIS_NA.STATUS = 'Not Assigned'
LEFT JOIN LCR_STATUS_HISTORY HIS_AtA ON req.LCR_REQUEST_ID = HIS_AtA.LCR_REQUEST_ID AND HIS_AtA.STATUS = 'Assigned to Attorney'
LEFT JOIN LCR_STATUS_HISTORY HIS_SUB ON req.LCR_REQUEST_ID = HIS_SUB.LCR_REQUEST_ID AND HIS_SUB.STATUS = 'Submitted'
LEFT JOIN LCR_STATUS_HISTORY HIS_SCIN ON req.LCR_REQUEST_ID = HIS_SCIN.LCR_REQUEST_ID AND HIS_SCIN.STATUS = 'Submission Complete-In Negotiation'
LEFT JOIN LCR_STATUS_HISTORY HIS_EXE ON req.LCR_REQUEST_ID = HIS_EXE.LCR_REQUEST_ID AND HIS_EXE.STATUS = 'Executed'
LEFT JOIN LCR_STATUS_HISTORY HIS_CONV ON req.LCR_REQUEST_ID = HIS_CONV.LCR_REQUEST_ID AND HIS_CONV.STATUS = 'Converted to amendment.'
LEFT JOIN LCR_STATUS_HISTORY HIS_DEAD ON req.LCR_REQUEST_ID = HIS_DEAD.LCR_REQUEST_ID AND HIS_DEAD.STATUS = 'Dead'
LEFT JOIN LCR_STATUS_HISTORY HIS_COMP ON req.LCR_REQUEST_ID = HIS_COMP.LCR_REQUEST_ID AND HIS_COMP.STATUS = 'Completed'
LEFT JOIN LCR_STATUS_HISTORY HIS_EXP ON req.LCR_REQUEST_ID = HIS_EXP.LCR_REQUEST_ID AND HIS_EXP.STATUS = 'Expired/Terminated'
WHERE REQ.CATEGORY_NAME = 'Sales'
AND
REQ.DATE_RECORDED BETWEEN to_date ('07/01/2012', 'mm/dd/yyyy') AND to_date ('06/30/2013','mm/dd/yyyy')
GROUP BY
req.LCR_REQUEST_ID
,req.MATTER_ID
,req.CUSTOMER_NAME
,req.STATUS
,HIS.RECORDED_DATE
--,HIS.STATUS
,HIS_SUB.RECORDED_DATE
--,HIS_NA.RECORDED_DATE
,HIS_AtA.RECORDED_DATE
,HIS_SCIN.RECORDED_DATE
,HIS_EXE.RECORDED_DATE
,HIS_CONV.RECORDED_DATE
,HIS_DEAD.RECORDED_DATE
,HIS_COMP.RECORDED_DATE
,HIS_EXP.RECORDED_DATE
,CASE
WHEN req.DEALSIZE = 0 THEN ''
WHEN req.DEALSIZE = 1 THEN 'Less Than 100K'
when req.DEALSIZE = 2 THEN '100K-500K'
when req.DEALSIZE = 3 THEN '500K-1M'
when req.DEALSIZE = 4 THEN '1M-10M'
when req.DEALSIZE = 5 THEN '>10M'
END
,cm_out.PTY_NAME
,cm_out.PTY_ID
,req.customer_id
,cm_out.EFFECTIVE_DATE
,cm_out.INITIALTERM_END_DATE
,cm_out.CONTRACT_TERMINATION_DATE
,cm_out.TERM_NOTICE_NONCOMP_REASON
,cm_out.TERM_TYPE
,cm_out.INITIALTERM_DURATION
,cm_out.INVOICE_TIMEMEAS
,cm_out.NUMBER_OF_RENEWALS
,req.AMENDMENT
,prod.rpg
,prod.SALES_PRODUCT_NAME
,prod.CONTRACT_TYPE
,req.CONTRACT_ROLE
,cm_out.METADATA_FLAG
,CASE
WHEN cm_out.DATA_AUTO_IMPORT_YN = 1 THEN 'YES'
WHEN cm_out.REQUESTOR = 'Imported Record' THEN 'YES'
ELSE 'NO'
END
,CASE act.actionstatus
WHEN 'Cancel Date Update' THEN 'Yes'
ELSE NULL
END
,req_emp.FIRST_NAME || ' ' || req_emp.LAST_NAME
,att_emp.FIRST_NAME || ' ' || att_emp.LAST_NAME
,req.REQUESTOR_DEPARTMENT
,req.AGREEMENT_TITLE
,req.DATE_RECORDED;
I wonder how you get multiple columns with a max date using a single TOP 1?
Most of the LEFT JOINs to LCR_STATUS_HISTORY can easily be replaced by a single join using MAX(CASE):
LEFT JOIN
(
SELECT LCR_REQUEST_ID,
MAX(CASE WHEN STATUS = 'Assigned to Attorney' THEN RECORDED_DATE END) AS "AssignedToAttorney_Status_Date"
,MAX(CASE WHEN STATUS = 'Submission Complete-In Negotiation' THEN RECORDED_DATE END) AS "InNegotiation_Status_Date"
,...
FROM LCR_STATUS_HISTORY
GROUP BY LCR_REQUEST_ID
) his
ON HIS.LCR_REQUEST_ID = req.LCR_REQUEST_ID
Then you probably don't need the GROUP BY any more.
And in this join-condition the OR-part can be removed:
((HIS.STATUS = REQ.STATUS) OR (HIS.STATUS = 'Assigned to Attorney' AND REQ.STATUS = 'Assigned To Attorney'))
ON HIS.LCR_REQUEST_ID = req.LCR_REQUEST_ID

How to change this 'Not In' Query to Left Join query

I've been trying to change this query. I don't want to use 'Not In' in this query. Can anybody help me how to change this query to left join query?
SELECT t.date,t.ticket,t.weight,t.Count, td.description
FROM tblticket t inner join tblticketdetails td on t.ticket = td.ticket
WHERE t.ticket NOT IN (SELECT r.Original_ticket from tblRenew R where isnull(r.new_ticket,'') = '' and r.transaction_status = 'valid')
AND RTRIM(LTRIM(t.status)) = 'OPEN'
AND td.Type = 62
AND t.weight/t.Count >= 1000
AND t.date BETWEEN '2011-12-31' AND '2013-01-17'
Providing that you don't have multiple records in tblRenew for any ticket:
select
t.date, t.ticket, t.weight, t.Count, td.description
from
tblticket t
inner join tblticketdetails td on t.ticket = td.ticket
left join tblRenew R on isnull(r.new_ticket,'') = '' and r.transaction_status = 'valid' and r.Original_ticket = t.ticket
where
r.Original_ticket is not null
and RTRIM(LTRIM(t.status)) = 'OPEN'
and td.Type = 62
and t.weight/t.Count >= 1000
and t.date BETWEEN '2011-12-31' AND '2013-01-17'
SELECT t.date, t.ticket,t.weight, t.Count, td.description
FROM tblticket t inner join
tblticketdetails td
on t.ticket = td.ticket left outer join
(SELECT r.Original_ticket
from tblRenew R
where isnull(r.new_ticket,'') = '' and
r.transaction_status = 'valid'
) v
on t.ticket = v.Original_ticket
WHERE t.ticket NOT IN (SELECT r.Original_ticket from tblRenew R where isnull(r.new_ticket,'') = '' and r.transaction_status = 'valid')
AND RTRIM(LTRIM(t.status)) = 'OPEN'
AND td.Type = 62
AND t.weight/t.Count >= 1000
AND t.date BETWEEN '2011-12-31' AND '2013-01-17'
and v.original_tiket is null