Hi Sahan,
try this
select OCLG.ClgCode AS 'ActivityNo',OCLG.CardCode as 'LeadCode',OCRD.CardName as 'Lead Name',OCLG.Notes as 'Activity Status',OCLG.Tel,OCLG.Details as 'Reason/Status',
OCPR.Name as 'Contact Person',OCLG.CntctDate,OCLO.Name,OCLG.DocNum as 'Document No',
OUSR.U_NAME as 'Activity Assigned To',
CASE OCLG.DocType
when (23)then 'Sales Quotation'
else 'Invalid Parameters' end AS 'Document Type (1)',
CASE oclg.Action
When ('C') then 'Phone Call'
when ('M') then 'Meeting'
when ('T')then 'Task'
when ('E')then 'Note'
when ('P')then 'Campaign'
when ('N')then 'Other'
else 'Invalid Parameters' end AS 'Activity Type (1)',
CASE OCLG.CntctType
when (-1) then 'General'
when (1) then 'Received E-mail'
when (3) then 'Follow Up: Phone'
when (2) then 'Follow Up: E-mail'
when (4) then 'Face to Face'
else 'Invalid Parameters' end AS 'Activity Type(2)',
CASE OCLG.Priority
WHEN (2) then 'High'
WHEN (0) then 'Low'
WHEN (1) then 'Normal'
else 'Invalid Parameters' end AS 'Activity Priority'
from OCLG
inner join OCRD on OCLG.CardCode=OCRD.CardCode
LEFT join OCPR on OCRD.CntctPrsn=OCPR.Name
Left Outer join OCLO ON OCLG.Location = OCLO.Code
inner join OUSR on OCLG.AttendUser = OUSR.USERID
--where ClgCode in(select top 1 max(ClgCode) from OCLG)
order by OCLG.ClgCode