Tom, Sugarthan, James
Many thanks for your prompt reply & help. I tried distinct, group by (with MAX()). But unfortunately I did not get the results I want.
I think its due to the complexity of my query. 3 columns out of 4 are formatted (compound) columns using fields from various tables. Here is my query.
I would appreciate if you could give some more help on this please.
Thanks
Sivi
set ansi_nulls off
select distinct
col1=c.an,
col2=dateadd(d,-day((cast(right(replicate('0',2)+convert(varchar(2),d.mID),2)+'/'+'01'+'/'+substring(b.cmonth,2,4) as datetime))),dateadd(m,1,(cast(right(replicate('0',2)+convert(varchar(2),d.mID),2)+'/'+'01'+'/'+substring(b.cmonth,2,4) as datetime) ))),
col3= case a.f when 'O' then b.rdate else ' ' end,
col4=convert(datetime, getdate(),112),
col5=case a.f when 'F' then b.rdate else ' ' end,
from cmast as b
join eq as a on b.ccode=a.ocode
join cli as c on b.ccode=c.clcod
join mcode as d on substring(b.cmonth,1,1)=d.contractmonthletter
where c.an is not NULL
and b.rdate>= dateadd(mm,-2,convert(char(8),getdate(),112))
and b.rdate<= dateadd(yy,1,convert(char(8),getdate(),112))
The results have to be unique on col 1,2,3 &5