Hi all,
From my query a result set like this is returned.
INCIDENT NO. OFFENSE NO. COMPLAINT DISP3 DATE ADDRESS
10 20 ... .... .... ...
10 25 ..... .... .... .....
10 30 .... ..... .... ....
20 50 .... ..... .... ....
I do not want to show any duplicates where all the fields are the same, nor do I want to show rows where they're the same except for the one field OFFENSE NO. I believe this is accomplished with row_number function along with partition by, but I'm not sure how to implement it.
SELECT a.incidentno as 'Incident No.', c.offenseno as 'Offense No.', a.Complaint, a.code3 as 'Disp3',
a.dtrecv as 'Date', a.caddress1 + ' APT/LOT#' + a.captlot as Address
FROM CALLHIST a LEFT OUTER JOIN CADCALL_UNIT b ON a.INCIDENTNO = b.INCIDENTNO
LEFT OUTER JOIN [###].dbo.[###] c ON a.INCIDENTNO = c.CAD_INCID LEFT OUTER JOIN [###].dbo.[###] d ON b.perno = d.perno
WHERE a.dtrecv >= '1/1/2002' and a.dtrecv <= '7/23/2015' order by a.dtrecv
Thanks.